做的是科研管理系统,页面如下图(很粗糙~凑合看吧)呵呵
单独每项提交到数据库,,如果发表的论文有两篇就按下提交两次了,所以就每项提交了(这是我想到的很笨的方法···)但是发现每项填完按下提交,数据不能传入数据库···
源代码截取两个事件如下:
protected void sciebutton1_Click(object sender, EventArgs e)
{
string conn = "server=PC-201005131654;database=Project;user id=sa;pwd=123";
SqlConnection cn = new SqlConnection(conn);
cn.Open();
/*科研表*/
string strsqlsawar = "insert into scient_reward (name,awards_level,rank,record) values ('" + scie_name.Text + "','" + awards_level.Text + "','" + scie_rank.SelectedItem.Text + "','" + scie_score.Text + "')";
SqlCommand cmdsawar = new SqlCommand(strsqlsawar, cn);
cmdsawar.ExecuteNonQuery(); }
protected void essayButton2_Click(object sender, EventArgs e)
{
string conn = "server=PC-201005131654;database=Project;user id=sa;pwd=123";
SqlConnection cn = new SqlConnection(conn);
cn.Open();
/*论文表*/
string strsqlessay = "insert into essay (subject,public_class,record) values ('" + subject.Text + "','" + essay_level.SelectedItem.Text + "','" + essay_score.Text + "')";
SqlCommand cmdessay = new SqlCommand(strsqlessay, cn);
cmdessay.ExecuteNonQuery();
} 谢谢各位了!
单独每项提交到数据库,,如果发表的论文有两篇就按下提交两次了,所以就每项提交了(这是我想到的很笨的方法···)但是发现每项填完按下提交,数据不能传入数据库···
源代码截取两个事件如下:
protected void sciebutton1_Click(object sender, EventArgs e)
{
string conn = "server=PC-201005131654;database=Project;user id=sa;pwd=123";
SqlConnection cn = new SqlConnection(conn);
cn.Open();
/*科研表*/
string strsqlsawar = "insert into scient_reward (name,awards_level,rank,record) values ('" + scie_name.Text + "','" + awards_level.Text + "','" + scie_rank.SelectedItem.Text + "','" + scie_score.Text + "')";
SqlCommand cmdsawar = new SqlCommand(strsqlsawar, cn);
cmdsawar.ExecuteNonQuery(); }
protected void essayButton2_Click(object sender, EventArgs e)
{
string conn = "server=PC-201005131654;database=Project;user id=sa;pwd=123";
SqlConnection cn = new SqlConnection(conn);
cn.Open();
/*论文表*/
string strsqlessay = "insert into essay (subject,public_class,record) values ('" + subject.Text + "','" + essay_level.SelectedItem.Text + "','" + essay_score.Text + "')";
SqlCommand cmdessay = new SqlCommand(strsqlessay, cn);
cmdessay.ExecuteNonQuery();
} 谢谢各位了!
你把动态生成的sql语句,直接放在数据库的查询分析器中执行,能插入数据吗?
另外你要确定你动态生成的sql语句在sqlserver查询分析器中,可以正确执行添加记录。
using(SqlConnection cn = new SqlConnection(conn))
{}