olecommand.CommandText = "insert into pic(p_name,p_sex,p_age,p_filename)
values (@pname,@psex,@page,@pfilename)";
olecommand.Parameters.Add("@pname", OleDbType.VarChar, 10);
olecommand.Parameters.Add("@psex", OleDbType.VarChar, 2);
olecommand.Parameters.Add("@page", OleDbType.Integer, 8);
olecommand.Parameters.Add("@pfilename", OleDbType.VarChar, 50);
olecommand.Prepare();
olecommand.Parameters["@pname"].Value = tname.Text.Trim ();
olecommand.Parameters["@psex"].Value = tsex.Text.Trim();
olecommand.Parameters["@page"].Value = tage.Text.Trim();
olecommand.Parameters["@pfilename"].Value = filename;提示 未能准备语句,必须声明变量:@pname....等
找了很多都没有弄懂,书上也没有找到类似的说明,请帮忙 !
values (@pname,@psex,@page,@pfilename)";
olecommand.Parameters.Add("@pname", OleDbType.VarChar, 10);
olecommand.Parameters.Add("@psex", OleDbType.VarChar, 2);
olecommand.Parameters.Add("@page", OleDbType.Integer, 8);
olecommand.Parameters.Add("@pfilename", OleDbType.VarChar, 50);
olecommand.Prepare();
olecommand.Parameters["@pname"].Value = tname.Text.Trim ();
olecommand.Parameters["@psex"].Value = tsex.Text.Trim();
olecommand.Parameters["@page"].Value = tage.Text.Trim();
olecommand.Parameters["@pfilename"].Value = filename;提示 未能准备语句,必须声明变量:@pname....等
找了很多都没有弄懂,书上也没有找到类似的说明,请帮忙 !
olecommand.Parameters.AddWithValue("?", tname.Text.Trim());
olecommand.Parameters.AddWithValue("?", tsex.Text.Trim());
olecommand.Parameters.AddWithValue("?", tage.Text.Trim());
olecommand.Parameters.AddWithValue("?", filename);
values (pname,psex,page,pfilename)";
olecommand.ExecuteNonQuery();就是简单的从textbox中得到值保存到pname,然后插入到数据库.......
请问有什么直接的方法吗,像这样?
不必到数据中建存储过程等..