SqlCommand myCommand = new SqlCommand();
myCommand.Connection=conn;
myCommand.CommandType = CommandType.Text;
myCommand.CommandText = "insert 接收人列表(UID,接收人名称)values(@id,@name)";
myCommand.Parameters.Add("@id",SqlDbType.VarChar,50,TextBox1.Text);
myCommand.Parameters.Add("@name",SqlDbType.VarChar,50,TextBox2.Text); int a = myCommand.Parameters.Count;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand= myCommand;
DataSet ds = new DataSet();
sda.Fill(ds);我这样 他提示被准备语句 '(@id varchar(50),@name varchar(50))insert 接收人列表(UID,接收人名称)values' 需要参数 @id,但未提供该参数。各位高手帮忙看看
myCommand.Connection=conn;
myCommand.CommandType = CommandType.Text;
myCommand.CommandText = "insert 接收人列表(UID,接收人名称)values(@id,@name)";
myCommand.Parameters.Add("@id",SqlDbType.VarChar,50,TextBox1.Text);
myCommand.Parameters.Add("@name",SqlDbType.VarChar,50,TextBox2.Text); int a = myCommand.Parameters.Count;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand= myCommand;
DataSet ds = new DataSet();
sda.Fill(ds);我这样 他提示被准备语句 '(@id varchar(50),@name varchar(50))insert 接收人列表(UID,接收人名称)values' 需要参数 @id,但未提供该参数。各位高手帮忙看看
解决方案 »
- 网站站点地图有些地方不太明白.. 就大侠解惑..(进者有分)
- GridViewRow定义问题
- 讨论是使用DataGrid还是表格!
- vs2005、sql2005与.net2.0配置问题
- table动态中添加一行数据如何实现
- 小弟很菜,想问下首页静态化,是怎么生成的啊?怎么加载数据?
- treeview如何实现隐藏某些节点,想了几天的,大家帮帮忙,真的感谢
- 请教为什么连接数据会提示找不到可安装的 ISAM
- 关于安装office和vs.net2003是否发生冲突的问题,请高手指教,谢谢!
- NHibernate执行SQL语句
- 关于Container的属性的问题?
- 再加一贴,200分求此问题正解,C#.NET关于树形菜单问题........急......
sda.SelectCommand= myCommand;把这两句改为一句:
SqlDataAdapter sda = new SqlDataAdapter(myCommand);
你这个command应该不是selectcommand而是insertcommand
直接用myCommand.ExecuteNonQuery()不就行了吗?
为什么还要用dataadapter和dataset
还是那个错误
sda.SelectCommand= myCommand;
DataSet ds = new DataSet();
sda.Fill(ds);这些都不要了
换成:
conn.Open();
myCommand.ExecuteNonQuery();
conn.Close();
异常问题你可以自己去处理
myCommand.Parameters.Add("@name",SqlDbType.VarChar,50,TextBox2.Text);---->//你看一下Add方法重载的参数就明白了,另外,学会看错误信息
myCommand.Parameters.Add("@id",TextBox1.Text);
myCommand.Parameters.Add("@name",TextBox2.Text);
insert into 表名 values(@id)
cmd.Parameters.Add("@id", SqlDbType.VarChar);
cmd.Parameters["@id"].Value = TextBox1.Text;
你这句忘写into 了吧
SqlConnection con = new SqlConnection(strcon);
if(con.State==0) con.Open();
SqlCommand cmd = new SqlCommand("insert into Users(姓名, 学历, Email,性别) values(@name,@pwd,@email,@sex)",con);
//cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@name",SqlDbType.NVarChar);
cmd.Parameters.Add("@pwd",SqlDbType.NVarChar);
cmd.Parameters.Add("@email",SqlDbType.NVarChar);
cmd.Parameters.Add("@sex",SqlDbType.Char);
cmd.Parameters["@name"].Value = text1.Text;
cmd.Parameters["@pwd"].Value = text2.Text;
cmd.Parameters["@email"].Value = text3.Text;
cmd.Parameters["@sex"].Value = text4.Text; text1.Text=string.Empty;
text2.Text =string.Empty;
text3.Text =string.Empty;
text4.Text=string.Empty;
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("数据插入成功");
看一看吧,这是我做的,在我这里没有问题哦,
这是在winform中写的哦,web中也一样的哦,,