本文整理汇总了C#中SqlDataSource.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDataSource.Insert方法的具体用法?C# SqlDataSource.Insert怎么用?C# SqlDataSource.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlDataSource
的用法示例。
在下文中一共展示了SqlDataSource.Insert方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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");
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
ArrayList al = (ArrayList)Session["AnswerList"];
if (al == null)
{
Response.Redirect("Exam.aspx");
}
resultGrid.DataSource = al;
resultGrid.DataBind();
// Save the results into the database.
try {
if (IsPostBack == false)
{
double questions = al.Count;
double correct = 0.0;
for (int i = 0; i < al.Count; i++)
{
Answer a = (Answer)al[i];
if (a.Result == Answer.ResultValue.Correct)
correct++;
}
double score = (correct / questions) * 100;
SqlDataSource userExamDataSource = new SqlDataSource();
userExamDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["OnlineExamConnectionString"].ToString();
userExamDataSource.InsertCommand = "INSERT INTO [StudentExam] ([ExamID], [DateTimeComplete], [Score], [Username]) VALUES (@ExamID, @DateTimeComplete, @Score, @Username)";
userExamDataSource.InsertParameters.Add("ExamID", Session["ExamID"].ToString());
userExamDataSource.InsertParameters.Add("DateTimeComplete", DateTime.Now.ToString());
userExamDataSource.InsertParameters.Add("Score", score.ToString());
userExamDataSource.InsertParameters.Add("Username", Session["Student"].ToString());
int rowsAffected = userExamDataSource.Insert();
}
}
catch(Exception){
errorLabel.Text ="There was a problem saving your quiz results into our database. Therefore, the results from this quiz will not be displayed on the list on the main menu.";
}
}
示例4: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource SqlDataSource1 = new SqlDataSource();
SqlDataSource1.ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataSource1.InsertParameters.Add("Order_date", TextBox1.Text);
SqlDataSource1.InsertParameters.Add("Assign_numbers", TextBox2.Text);
SqlDataSource1.InsertParameters.Add("Account_numbers", DropDownList1.Text);
SqlDataSource1.InsertParameters.Add("Account_abstract", TextBox3.Text);
SqlDataSource1.InsertParameters.Add("Income", TextBox4.Text);
SqlDataSource1.InsertParameters.Add("Spend", TextBox5.Text);
SqlDataSource1.InsertCommand = "Insert into Account_Order_M(Order_date,Assign_numbers,Account_numbers,Account_abstract,Income,Spend) values(@Order_date,@Assign_numbers,@Account_numbers,@Account_abstract,@Income,@Spend)";
int affraw = SqlDataSource1.Insert();
if (affraw == 0)
{
Label1.Text = "Error";
}
else
{
Label1.Text = "OK";
Button1.Visible = false;
}
SqlDataSource1.Dispose();
}
示例5: 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();
}
}
}
示例6: Button_Submit_Click
protected void Button_Submit_Click(object sender, EventArgs e)
{
String Route1 = Request.QueryString["Route1"];
String Route2 = Request.QueryString["Route2"];
String Seat_Q_R1 = Request.QueryString["S_R1"];
String Seat_Q_R2 = Request.QueryString["S_R2"];
String R1 = "";
String R2 = "";
String[] Seat_R1 = { };
String[] Seat_R2 = { };
if (Seat_Q_R1 != null)
{
if (Seat_Q_R1.ToString() != "")
{
Seat_R1 = Seat_Q_R1.Split('_');
}
}
if (Seat_Q_R2 != null)
{
if (Seat_Q_R2.ToString() != "")
{
Seat_R2 = Seat_Q_R2.Split('_');
}
}
if (Route1 != null)
{
if (Route1.ToString() != "")
{
R1 = Route1;
}
}
if (Route2 != null)
{
if (Route2.ToString() != "")
{
R2 = Route2;
}
}
set_seat(); // set Seat to จอง
SqlDataSource Res = new SqlDataSource();
Res.ConnectionString =
ConfigurationManager.ConnectionStrings["BusTicketConnectionString1"].ToString();
Res.InsertCommand = "INSERT INTO [Reservation] ([Member_UserName], [Res_Name], "
+"[Res_Sex], [Res_Phone], [Res_R1], [Res_Price_R1], [Res_R2], [Res_Price_R2], "
+ "[Res_Serviece_Price], [Res_Sum_Price], [Res_Status], [Res_Seat_Name_R1], [Res_Seat_Name_R2]) "
+"VALUES (@Member_UserName, @Res_Name, @Res_Sex, @Res_Phone, @Res_R1, "
+ "@Res_Price_R1, @Res_R2, @Res_Price_R2, @Res_Serviece_Price, @Res_Sum_Price, @Res_Status, @Res_Seat_Name_R1, @Res_Seat_Name_R2)";
Res.InsertParameters.Clear();
Res.InsertParameters.Add("Member_UserName", User.Identity.Name.ToString());
Res.InsertParameters.Add("Res_Name", TextBox_Name.Text + " " + TextBox_LastName.Text);
Res.InsertParameters.Add("Res_Sex", RadioButtonList_Sex.SelectedValue);
Res.InsertParameters.Add("Res_Phone", TextBox_Phone.Text);
Res.InsertParameters.Add("Res_R1", R1);
Res.InsertParameters.Add("Res_R2", R2);
Res.InsertParameters.Add("Res_Seat_Name_R1", (String)Session["Seat_R1"]);
Res.InsertParameters.Add("Res_Seat_Name_R2", (String)Session["Seat_R2"]);
Res.InsertParameters.Add("Res_Price_R1", Label_price_R1.Text);
Res.InsertParameters.Add("Res_Price_R2", Label_price_R2.Text);
Res.InsertParameters.Add("Res_Serviece_Price", Label_serviece_price_SUM.Text);
Res.InsertParameters.Add("Res_Sum_Price", Label_price_SUM_ALL.Text);
Res.InsertParameters.Add("Res_Status", "ค้างชำระ");
Res.Insert();
int ID = get_Res_ID_Last();
SqlDataSource Res_Seat = new SqlDataSource();
Res_Seat.ConnectionString =
ConfigurationManager.ConnectionStrings["BusTicketConnectionString1"].ToString();
Res_Seat.InsertCommand = "INSERT INTO [Res_Seat] ([Res_ID], [Seat_ID]) "
+ "VALUES (@Res_ID, @Seat_ID)";
if (Route1 != null)
{
if (Route1.ToString() != "")
{
for (int i = 0; i < Seat_R1.Length; i++)
{
Res_Seat.InsertParameters.Clear();
Res_Seat.InsertParameters.Add("Res_ID", ID.ToString());
int Sead_ID = get_Seat_ID(Route1, Seat_R1[i]);
Res_Seat.InsertParameters.Add("Seat_ID", Sead_ID.ToString());
Res_Seat.Insert();
}
}
}
if (Route2 != null)
{
if (Route2.ToString() != "")
{
for (int i = 0; i < Seat_R2.Length; i++)
{
Res_Seat.InsertParameters.Clear();
//.........这里部分代码省略.........