如何在dbparameter中添加command.parameters.addwithvalue? [英] how to add command.parameters.addwithvalue in dbparameter?
本文介绍了如何在dbparameter中添加command.parameters.addwithvalue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我想在dbconnection中添加command.parameters.addwithvalue,dbparameter
请告诉我怎么可能
解决方案
sqlcommand cmd = new sqlcommand();
cmd.parameters.addwithvalue(@ value,value);
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = commandType;
cmd.CommandText = commandText;
foreach(参数中的SqlParameter参数)
{
cmd.Parameters.Add(param);
}
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable results = new DataTable();
conn.Open();
adapter.Fill(results);
conn.Close();
返回结果;
使用con作为新的SqlConnection(constr)
使用cmd作为新的SqlCommand(INSERT INTO tab1(Col1,Col2)VALUES(@ Name,@ Country) )
cmd.Parameters.AddWithValue(@ Name,1)
cmd.Parameters.AddWithValue(@ Country,2)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End using
End using
hello i want to add command.parameters.addwithvalue in dbconnection, dbparameter
please let me know how it is possible解决方案sqlcommand cmd=new sqlcommand();
cmd.parameters.addwithvalue("@value",value);
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = commandType;
cmd.CommandText = commandText;
foreach (SqlParameter param in parameters)
{
cmd.Parameters.Add(param);
}
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable results = new DataTable();
conn.Open();
adapter.Fill(results);
conn.Close();
return results;
Using con As New SqlConnection(constr) Using cmd As New SqlCommand("INSERT INTO tab1 (Col1, Col2) VALUES (@Name, @Country)") cmd.Parameters.AddWithValue("@Name", "1") cmd.Parameters.AddWithValue("@Country", "2") cmd.Connection = con con.Open() cmd.ExecuteNonQuery() con.Close() End Using End Using
这篇关于如何在dbparameter中添加command.parameters.addwithvalue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文