如何通过windows窗体将字符串插入sql server表
本文关键字:插入 sql server 字符串 何通过 windows 窗体 | 更新日期: 2023-09-27 18:14:07
我有一个sql server表位于我的网站(远程)。这个表叫做table1
,它有一个字段叫做f1
。这里我的目标是用一个签名如下的c#方法将字符串"hello there"插入其中:
AddTof1(string s)
{
}
任何想法?
AddTof1(string s)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand("INSERT INTO table1 values(@s)", connection))
{
command.Parameters.AddWithValue("@s", s);
command.ExecuteNonQuery();
}
}
}
然后你可以调用这个方法为;
AddTof1("hello there");