C# 在数据库中插入列表

C# 在数据库中插入列表,c#,winforms,ms-access-2010,C#,Winforms,Ms Access 2010,我在richtextbox ex中有一个列表: dogs cats books other 如何在表“动物”中的“主页”列中插入一行?类似于以下内容: }请给提问者一个机会,让他们自己找出答案。@jolly-那么你希望有人给你一个工作代码示例,而不让你自己做任何工作?颜色让我惊讶。我插入了一个连接提供程序=MSDataShape;数据提供者=Microsoft.Jet.OLEDB.4.0;数据源=数据库\\Database.mdb;Jet OLEDB:数据库密码=1234 string co

我在richtextbox ex中有一个列表:

dogs
cats 
books
other
如何在表“动物”中的“主页”列中插入一行?

类似于以下内容:


}

请给提问者一个机会,让他们自己找出答案。@jolly-那么你希望有人给你一个工作代码示例,而不让你自己做任何工作?颜色让我惊讶。我插入了一个连接提供程序=MSDataShape;数据提供者=Microsoft.Jet.OLEDB.4.0;数据源=数据库\\Database.mdb;Jet OLEDB:数据库密码=1234
string connectionString ="yourConnectionString"
using (DbConnection conn = new OdbcConnection(connectionString))
using (DbCommand cmd = conn.CreateCommand())
{
  cmd.CommandText = "INSERT INTO Animals(home) VALUES (@animal)";
  DbParameter p = cmd.CreateParameter();
  p.ParameterName = "@animal";
  cmd.CommandType = CommandType.Text;
  conn.Open();
  using (DbTransaction tran = conn.BeginTransaction())
 {
     cmd.Transaction = tran;
     try
     {
         foreach (string line in MyRichTextBox.Lines)
         {
            p.Value = line;
            cmd.ExecuteNonQuery();
         }
         tran.Commit();
         conn.Close();
     }
     catch (Exception e)
     {
         tran.Rollback();
        throw(e);
     }
 }