关于c# 向sql server insert 数据问题的,在线等,急!!!!!!!!!!!!!!!!!
SqlConnection thisConnection = new SqlConnection(@"server=.\SQLEXPRESS;AttachDbFilename=C:\Users\DY\Documents\PMS.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
thisConnection.Open();
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "insert into [personal info] Values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + OwnerPic + "')";
thisCommand.ExecuteNonQuery();//执行插入语句
thisConnection.Close();
thisConnection.Dispose();
MessageBox.Show("new owner has been registered successful!");
每次执行提示VHOST出错,问题出现在什么地方?请指点
OwnPic在数据库当中类型为image,insert里这样写对吗?
------解决方案--------------------
thisCommand.CommandText = "insert into [personal info] Values(@name1,@name2,@name2)";
thisCommand.Parameters.AddWithValue("@name1",TextBox1.Text);
thisCommand.Parameters.AddWithValue("@name2",TextBox1.Text);
thisCommand.Parameters.AddWithValue("@name3",OwnerPic );
thisCommand.ExecuteNonQuery();
等参数化方法实现
参见
http://dotnet.aspx.cc/file/Upload-Image-To-Access-With-C-Sharp-And-VB.NET.aspx
------解决方案--------------------[personal info] - 数据库表名能中间能有空格吗?
------解决方案--------------------在数据库当中类型为image的字段不能直接用拼接的sql语句,需要参数化