本文整理汇总了C#中SqlDataSource类的典型用法代码示例。如果您正苦于以下问题:C# SqlDataSource类的具体用法?C# SqlDataSource怎么用?C# SqlDataSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlDataSource类属于命名空间,在下文中一共展示了SqlDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnUpdate_Click
//按鈕更新
protected void btnUpdate_Click(object sender, EventArgs e)
{
//壓縮圖片並存檔
CImageProess.get().UploadImage(FileUpload1, 資料夾路徑, CDictionary.SET_BRAND_PX);
x = new SqlDataSource();
x.ConnectionString = CDictionary.CONN_URL;
string sql = "UPDATE Company set ";
if (!string.IsNullOrEmpty(txtContent.Text))
{
sql += " name=N'" + txtName.Text + "', ";
if (FileUpload1.HasFile)
sql += " picBrandPath='" + CImageProess.imageName + "', ";
sql += " manager=N'" + txtManager.Text + "', ";
sql += " tel=N'" + txtPhone.Text + "', ";
sql += " sparEmail=N'" + txtSpareEmail.Text + "', ";
sql += " addr=N'" + txtAddress.Text + "', ";
sql += " content=N'" + txtContent.Text + "' ";
sql += "WHERE companyID='" + companyID + "'";
x.UpdateCommand = sql;
x.Update();
}
else
return;
Response.Write("<script>alert('更改資料成功!')</script>");
Response.Write("<script>location.href='companyCheck.aspx'</script>");
}
示例2: btnAdd_Click
protected void btnAdd_Click(object sender, EventArgs e)
{
SqlDataSource sql1 = new SqlDataSource();
sql1 = SqlDataSource1;
SqlDataSource1.InsertParameters["Course_id"].DefaultValue = TextBox3.Text;
SqlDataSource1.InsertParameters["Assignment"].DefaultValue = TextBox8.Text;
SqlDataSource1.InsertParameters["Subject_id"].DefaultValue = TextBox4.Text;
SqlDataSource1.InsertParameters["Instructor"].DefaultValue = TextBox5.Text;
SqlDataSource1.InsertParameters["Instructor_rank"].DefaultValue = Convert.ToString(TextBox6.Text);
SqlDataSource1.InsertParameters["Due_Date"].DefaultValue = TextBox9.Text;
try
{
SqlDataSource1.Insert();
TextBox3.Text = "";
TextBox8.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox9.Text = "";
}
catch (Exception ex)
{
lblError.Text = "A DB error has occurred. " + "Message: " + ex.Message;
}
}
示例3: DetailsView_Route_has_Bus_ItemUpdating
protected void DetailsView_Route_has_Bus_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
String Route_has_Bus_ID = DetailsView_Route_has_Bus.SelectedValue.ToString();
DropDownList D_Bus_ID_NEW = (DropDownList)DetailsView_Route_has_Bus.FindControl("DropDownList3");
DropDownList D_Bus_ID_OLD = (DropDownList)DetailsView_Route_has_Bus.FindControl("DropDownList7");
String Bus_ID_NEW = D_Bus_ID_NEW.SelectedValue;
String Bus_ID_OLD = D_Bus_ID_OLD.SelectedValue;
if (Bus_ID_NEW != Bus_ID_OLD)
{
delete_seat(Route_has_Bus_ID);
SqlDataSource seat = new SqlDataSource();
seat.ConnectionString =
ConfigurationManager.ConnectionStrings["BusTicketConnectionString1"].ToString();
String count_seat = get_seat_count(Bus_ID_NEW).ToString();
String command = "";
command = get_insert_command(count_seat, Route_has_Bus_ID);
if (command != "")
{
String insertCommand = "INSERT INTO [Seat] "
+ " (Route_has_Bus_ID, Seat_Number, Seat_Name, Seat_Status) "
+ " VALUES "
+ command
+ ";";
seat.InsertCommand = insertCommand;
seat.Insert();
}
}
}
示例4: DetailsView_Route_has_Bus_ItemInserted
protected void DetailsView_Route_has_Bus_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
DropDownList BS = (DropDownList)DetailsView_Route_has_Bus.FindControl("DropDownList5");
SqlDataSource seat = new SqlDataSource();
seat.ConnectionString =
ConfigurationManager.ConnectionStrings["BusTicketConnectionString1"].ToString();
String count_seat = get_seat_count(BS.SelectedValue).ToString();
String command = "";
String Route_has_Bus_ID = get_Route_has_Bus_ID_Last().ToString();
command = get_insert_command(count_seat, Route_has_Bus_ID);
if (command != "")
{
String insertCommand = "INSERT INTO [Seat] "
+ " (Route_has_Bus_ID, Seat_Number, Seat_Name, Seat_Status) "
+ " VALUES "
+ command
+ ";";
seat.InsertCommand = insertCommand;
seat.Insert();
}
Response.Redirect(Request.RawUrl);
}
示例5: Login1_Authenticate
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string conString = "Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\Yummy.mdf;Integrated Security=True";
string selectString = "SELECT * FROM tb_Userinfo WHERE Username='" + Login1.UserName + "'";//select string for search currency name correspond with the input
SqlDataSource dsrc = new SqlDataSource(conString, selectString);
DataView DV = (DataView)dsrc.Select(DataSourceSelectArguments.Empty);
if (DV.Table.Rows.Count > 0)
{
string password = (string)DV.Table.Rows[0][7];
if (password.Equals(Login1.Password))
{
//Label1.Text = "Congratulations! Login succeed! Please wait for redirect to Homepage!";
Session["Username"] = Login1.UserName;
Session["Call"] = DV.Table.Rows[0][1].ToString();
Server.Transfer("~/WebSite2/Default.aspx");
//Response.Write("<script language=javascript>alert('Congratulations! Login succeed!')</script>");
//System.Threading.Thread.Sleep(5000);
//Response.Redirect("~/WebSite2/Default.aspx");
}
else
e.Authenticated = false;
}
else
e.Authenticated = false;
}
示例6: FrmDataSourceWizard_Load
private void FrmDataSourceWizard_Load(object sender, EventArgs e)
{
var sds = new SqlDataSource("ConnectionString");
var ccc = new ConfigureConnectionContext();
SqlDataSourceUIHelper.ConfigureConnection(sds, ccc);
}
示例7: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
String userName = Session["Username"].ToString();
string conString = "Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\Yummy.mdf;Integrated Security=True";
string selectString = "SELECT * FROM [tb_Userinfo] WHERE Username='" + userName + "'";//select string for search currency name correspond with the input
SqlDataSource dsrc = new SqlDataSource(conString, selectString);
DataView DV = (DataView)dsrc.Select(DataSourceSelectArguments.Empty);
username.Text = DV.Table.Rows[0][6].ToString();
Call.Text = DV.Table.Rows[0][1].ToString();
email.Text = DV.Table.Rows[0][3].ToString();
Phone.Text = DV.Table.Rows[0][5].ToString();
if(DV.Table.Rows[0][2].ToString()=="Male")
RadioGenderList.Items[0].Selected=true;
else
RadioGenderList.Items[1].Selected = true;
switch (DV.Table.Rows[0][4].ToString())
{
case "BuCentral": RadioAreaList.Items[1].Selected = true; break;
case "BuWest": RadioAreaList.Items[0].Selected = true; break;
case "BuEast": RadioAreaList.Items[2].Selected = true; break;
case "BuOther": RadioAreaList.Items[3].Selected = true; break;
}
Register.Text = "Update";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
示例8: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource sqldatasource2 = new SqlDataSource();
sqldatasource2.ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString();
sqldatasource2.UpdateParameters.Add("Order_date", TextBox1.Text);
sqldatasource2.UpdateParameters.Add("Assign_numbers", TextBox2.Text);
sqldatasource2.UpdateParameters.Add("Account_numbers", DropDownList1.Text);
sqldatasource2.UpdateParameters.Add("Account_abstract", TextBox3.Text);
sqldatasource2.UpdateParameters.Add("Income", TextBox4.Text);
sqldatasource2.UpdateParameters.Add("Spend", TextBox5.Text);
sqldatasource2.UpdateCommand = "Update [Account_Order_M] set [email protected]_date, [email protected]_numbers, [email protected]_numbers, [email protected]_abstract, [email protected], [email protected] where Id="+Request["Id"];
int affraw_update = sqldatasource2.Update();
if (affraw_update == 0)
{
Label1.Text = "error";
}
else
{
Label1.Text = "ok";
Button1.Visible = false;
}
sqldatasource2.Dispose();
}
示例9: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource SqlDataSource2 = new SqlDataSource();
SqlDataSource2.ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
try
{
SqlDataSource2.DeleteCommand = "delete [Account_Order_M] where id=" + Request["Id"];
int affraw = SqlDataSource2.Delete();
if (affraw == 0)
{
Label8.Text = "error";
Button1.Visible = false;
}
else
{
Label8.Text = "ok";
Button1.Visible = false;
}
}
catch (Exception ex2)
{
Response.Write(ex2.ToString());
}
finally
{
SqlDataSource2.Dispose();
}
}
示例10: excuteNonQuery
private void excuteNonQuery(string sql)
{
SqlDataSource x = new SqlDataSource();
x.ConnectionString = @"Data Source=iii0.database.windows.net;Initial Catalog=prjTRK;Persist Security Info=True;User ID=iii;[email protected]";
x.InsertCommand = sql;
x.Insert();
Response.Redirect("~/windowCompany/companyCheck.aspx");
}
示例11: delete_seat
protected void delete_seat(String Route_has_Bus_ID)
{
SqlDataSource seat = new SqlDataSource();
seat.ConnectionString =
ConfigurationManager.ConnectionStrings["BusTicketConnectionString1"].ToString();
seat.DeleteCommand = "DELETE FROM [Seat] WHERE Route_has_Bus_ID = " + Route_has_Bus_ID;
seat.Delete();
}
示例12: DeleteBtn_Click
protected void DeleteBtn_Click(object sender, EventArgs e)
{
//ɾ���ݸ�
int formID = (int)this.ViewState["ObjectId"];
this.PersonalReimburseBLL.DeleteFormTravelReimburse(formID);
this.Page.Response.Redirect("~/Home.aspx");
SqlDataSource sds = new SqlDataSource();
}
示例13: LinkButton2_Click
protected void LinkButton2_Click(object sender, EventArgs e)
{
int code = Convert.ToInt32((sender as LinkButton).ToolTip.ToString());
string sql = "select (select top 1 m_fa_name from tbl_modules where m_id = tbl_groups_permission.gd_module_link) as [نام ماژول] , gd_blocked as [قفل] from tbl_groups_permission where tbl_groups_permission.gd_tbl_groups_link = " + code.ToString() + " order by gd_blocked desc";
SqlDataSource sds = new SqlDataSource(new main_class().get_connection_string(), sql);
GridView4.DataSource = sds;
GridView4.DataBind();
}
示例14: Bind
private void Bind()
{
SqlDataSource SqlDataSource1 = new SqlDataSource();
this.Page.Controls.Add(SqlDataSource1);
SqlDataSource1.ConnectionString = "Data Source=W8-RKOEN;Initial Catalog=PrinterMigration;User ID=sa;[email protected]";
SqlDataSource1.SelectCommand = "SELECT * FROM Main Order By Floor";
GridView1.DataSource = SqlDataSource1;
GridView1.DataBind();
}
示例15: executeQuery
private void executeQuery()
{
x = new SqlDataSource();
x.ConnectionString = @"Data Source=iii0.database.windows.net;Initial Catalog=prjTRK;Persist Security Info=True;User ID=iii;[email protected]";
x.SelectCommand = "Select * from Company where companyID='" + companyID + "'";
DataView dv = x.Select(DataSourceSelectArguments.Empty) as DataView;
txtCounterInput.Text = dv.Table.Rows[0]["name"].ToString();
}