ios降级不用电脑可以吗:ASP.NET(C#)+SQL的问题

来源:百度文库 编辑:高考问答 时间:2024/05/03 08:10:07
最近在做毕业设计,遇到麻纺了,希望大家帮我看看这个有没有什么错误,怎么老是不能写入数据库也不报错呢?

private void bt_save_Click(object sender, System.EventArgs e)
{
string jch_danwei = "'" + this.txt_jchdanwei.Text.Trim() + "',";
string jch_person = "'" + this.txt_jchperson.Text.Trim() + "',";
string bch_danwei = "'" + this.txt_bchdanwei.Text.Trim() + "',";
string bch_person = "'" + this.txt_bchperson.Text.Trim() + "',";
string jch_problem = "'" + this.txt_problem.Text.Trim() + "',";
string jch_command = "'" + this.txt_command.Text.Trim() + "',";
string jch_situation = "'" + this.txt_situation.Text.Trim()+ "'";
string jch_time = "'" + this.list_Year.SelectedItem.Text + "/"
+ this.list_Month.SelectedItem.Text + "/"
+ this.list_Day.SelectedItem.Text +"',";
try
{
if (theID.Value.Length > 0)
{strSQL = "update jiancha set"+
"jch_time=" + jch_time +
"jch_danwei=" + jch_danwei+
"jch_person=" + jch_person +
"bch_danwei=" + bch_danwei +
"bch_person=" + bch_person +
"jch_problem=" + jch_problem +
"jch_command=" + jch_command +
"jch_situation=" + jch_situation +
" where id='" + theID.Value.Trim() + "'";
Utility.Execute(strSQL);
}
else
{
string strSQL = "insert into jiancha values ("+jch_time+jch_danwei+jch_person+bch_danwei+bch_person+jch_problem+jch_command+jch_situation+")";
Utility.Execute(strSQL);

this.txt_jchdanwei.Text = "";
this.txt_jchperson.Text = "";
this.txt_bchdanwei.Text = "";
this.txt_bchperson.Text = "";
this.txt_problem.Text = "";
this.txt_command.Text = "";
this.txt_situation.Text = "";
}
this.ErrorMsg.Text = "数据保存成功!";
this.ErrorMsg.Visible = true;
}
catch
{
this.ErrorMsg.Text = "保存时出错,请重新输入!";
this.ErrorMsg.Visible = true;
}
}

楼主 你的插入语句格式可以这么写的
插入格式和pansyqiang不同

但是插入语句本身似乎有问题,如果用insert into Table values(....)则必须把所有的字段值都插入,否则就必须要用insert into Table(字段,...) values(对应字段值,...),并且字段类型如果为字符型,字段值必须要用单引号,数字类型的直接写,日期类型的要to_date('2006-02-01','yyyy-mm-dd')转换,我用的是oracle,其他的数据库日期类型转换不是这样。

不是专门搞.net的,只能从sql语句中帮你分析,所以回答的可能不正确。

我也在做毕业设计,呵呵,这是我的插入代码,希望有帮助
另外你的sql语句格式不对
string query = "insert into userinfo(username,nickname,password,email,major) values ( @username,@nickname,@password,@email,@major)";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = conn;
SqlParameter sp1 = new SqlParameter("@username", SqlDbType.Char, 255);
sp1.Direction = ParameterDirection.Input;
cmd.Parameters.Add(sp1);
SqlParameter sp2 = new SqlParameter("@nickname", SqlDbType.Char, 255);
sp2.Direction = ParameterDirection.Input;
cmd.Parameters.Add(sp2);
SqlParameter sp3 = new SqlParameter("@password", SqlDbType.Char, 255);
sp3.Direction = ParameterDirection.Input;
cmd.Parameters.Add(sp3);
SqlParameter sp4 = new SqlParameter("@email", SqlDbType.Char, 255);
sp4.Direction = ParameterDirection.Input;
cmd.Parameters.Add(sp4);
SqlParameter sp5 = new SqlParameter("@major", SqlDbType.Char, 255);
sp5.Direction = ParameterDirection.Input;
cmd.Parameters.Add(sp5);
sp1.Value = username;
sp2.Value = nickname;
sp3.Value = password;
sp4.Value = email;
sp5.Value = major;
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ee)
{
if (ee != null)
errstr = ee.Message;
}
cmd.Dispose();
conn.Close();
return errstr;