问题描述
在数据库中插入记录之前如何在会话中存储该值。
在Gridview中如下
学院名称问题1问题2问题3问题4
Ram Dropdownlist1 Dropdownlist2 Dropdownlist3 Dropdownlist4
Sam Dropdownlist5 Dropdownlist6 Dropdownlist7 Dropdownlist8
我有一个名为Submit的按钮。
当我点击提交时我想在数据库中保存以上gridview记录。
每个Dropdrodown有四个项目如下:差劲很好很好
1个很差
2个公平
3个很好
4优秀
例如当用户选择数据库1中的穷人意味着要保存时。
教师表格strcutre如下
id Autoincrement
FacName varchar(50)
Question1 int
Question2 int
Question3 int
Question4 int
在教师表中记录如下
id FacName Question1 Question2 Question3 Question4
1 Ram 4 2 3 1
2 Sam 3 4 1 2
提交按钮代码如下
string facname;
string d1,d2,d3,d4,d5
for(int i = 0; I< gvfaculty.rows.count;> {
DropDownList ddl1 =(DropDownList)gvfaculty.Rows [i] .FindControl(DropDownList1);
DropDownList ddl2 =(DropDownList)gvfaculty.Rows [i]。 FindControl(DropDownList2);
DropDownList ddl3 =(DropDownList)gvfaculty.Rows [i] .FindControl(DropDownList3);
DropDownList ddl4 =(DropDownList)gvfaculty .Rows [i] .FindControl(DropDownList4);
DropDownList ddl5 =(DropDownList)gvfaculty.Rows [i] .FindControl(DropDownList5);
facname = gvfaculty.Rows [i] .Cells [0] .Text.ToString();
d1 = ddl1.SelectedValue.ToString();
d2 = ddl2.SelectedValue.ToString();
d3 = ddl3.SelectedValue.ToString();
d4 = ddl4.SelectedValue.ToString();
d5 = ddl5.SelectedValue.ToString();
sql =插入教师表值('+ facname.tostring()+ , '+ d1 +','+ d2 +','+ d3 +','+ d4 +');
scon.Error ="" ;;
scon.ExecSql(sql);
if(scon.Error.ToString()! ="" ;;)
{
Lblmsg.Text = scon.Error.ToString();
return;
}
}
Lblmsg.Text ="已插入";
scon.Con.Close();
}
catch(exception ex2)
{
Lblmsg.Text = ex2。 ToString();
返回;
}
在数据库中插入值之前。我想将这些值保存到会话中,然后将该会话值传递给插入查询。
我怎样才能在asp.net中使用c#。
问候,
Jegan B
Before inserting the record in database how to store that value in session.
In Gridview as follows
Faculty Name Question1 Question2 Question3 Question4
Ram Dropdownlist1 Dropdownlist2 Dropdownlist3 Dropdownlist4
Sam Dropdownlist5 Dropdownlist6 Dropdownlist7 Dropdownlist8
I have one button called Submit.
When i click the Submit i want to save above gridview records in database.
For each Dropdrodown four items as follows Poor Fair Good Excellent
For 1 Being Poor
For 2 Being Fair
For 3 Being Good
For 4 Being Excellent
For example when user select the Poor means in Database 1 value to be saved.
Faculty Table strcutre as follows
id Autoincrement
FacName varchar(50)
Question1 int
Question2 int
Question3 int
Question4 int
In Faculty Table record as follows
id FacName Question1 Question2 Question3 Question4
1 Ram 4 2 3 1
2 Sam 3 4 1 2
Submit button code as follows
string facname;
string d1, d2, d3, d4, d5
for(int i = 0; i<gvfaculty.rows.count;> {
DropDownList ddl1 = (DropDownList)gvfaculty.Rows[i].FindControl("DropDownList1");
DropDownList ddl2 = (DropDownList)gvfaculty.Rows[i].FindControl("DropDownList2");
DropDownList ddl3 = (DropDownList)gvfaculty.Rows[i].FindControl("DropDownList3");
DropDownList ddl4 = (DropDownList)gvfaculty.Rows[i].FindControl("DropDownList4");
DropDownList ddl5 = (DropDownList)gvfaculty.Rows[i].FindControl("DropDownList5");
facname = gvfaculty.Rows[i].Cells[0].Text.ToString();
d1 = ddl1.SelectedValue.ToString();
d2 = ddl2.SelectedValue.ToString();
d3 = ddl3.SelectedValue.ToString();
d4 = ddl4.SelectedValue.ToString();
d5 = ddl5.SelectedValue.ToString();
sql = insert into Faculty Table values('" + facname.tostring() +"','" + d1 + "','" + d2 +"','" + d3 +"','" + d4 +"')";
scon.Error = "";
scon.ExecSql(sql);
if(scon.Error.ToString() != "";)
{
Lblmsg.Text = scon.Error.ToString();
return;
}
}
Lblmsg.Text = "Inserted";
scon.Con.Close();
}
catch (Exception ex2)
{
Lblmsg.Text = ex2.ToString();
return;
}
Before inserting the values in database. i want to save that values into session and then pass that session values into insert query.
for that how can i do in asp.net using c#.
Regards,
Jegan B
这篇关于在数据库中插入记录之前如何在会话中存储该值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!