C# 如何通过windows窗体将字符串插入sql server表?

C# 如何通过windows窗体将字符串插入sql server表?,c#,sql-server,winforms,C#,Sql Server,Winforms,我的网站上有一个sql server表(远程)。该表称为table1,它有一个名为f1的字段。我的目标是使用C#方法将字符串“hello there”插入其中,签名如下: AddTof1(string s) { } 有什么想法吗 AddTof1(string s) { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open();

我的网站上有一个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");

到目前为止你有试过什么吗?先表现出你的努力,这样人们才能表现出他们的努力。请阅读,如果你想让回答者也这样做,你需要在你的问题上投入更多的时间和精力。@我想发表评论,这样我就可以知道哪里可能错了?谢谢,我不需要登录位,因为这在我的程序的其他地方已经完成了。“@”字符是做什么的?是否需要?@John
@
字符用于匹配查询中的参数。在这种情况下,查询中的
@s
参数与方法中的
s
变量相匹配。@John谢谢。我想你被否决了,因为你屈尊回答了我的noob问题。哈哈。无论如何,谢谢。