初学,50分问个小问题:数据无法更新
private void btnEdit_Click(object sender, System.EventArgs e)
{
SqlConnection MyConnection = new SqlConnection("server = server\\lj;database=fujimi;user id=sa;password=lujia");
string UpdateCommand = "update News set news_name = '@nName',news_Author='@nAuthor',news_Ptime='@nPtime',news_content='@nContent' where news_Name=@name";
SqlCommand MyCommand = new SqlCommand(UpdateCommand,MyConnection);
MyCommand.Parameters.Add("@nName", SqlDbType.Char).Value = news_txtName.Text;
MyCommand.Parameters.Add("@nAuthor", SqlDbType.Char).Value = news_txtAuthor.Text;
MyCommand.Parameters.Add("@nPtime", SqlDbType.Char).Value = news_txtPtime.Text;
MyCommand.Parameters.Add("@ncontent", SqlDbType.Text).Value = news_txtcontent.Text;
MyConnection.Open();
try
{
MyCommand.ExecuteNonQuery();
Message.Text = "修改成功";
}
catch (SqlException)
{
Message.Text = "错误: 无法修改数据纪录";
}
MyConnection.Close();
}
测试时,总是无法更新。
还一个问题,我用FileName = Request.PhysicalApplicationPath + "test.doc"; 显示txt正常,但显示word就是乱码??求解。谢谢