27,581
社区成员




using System;
using System.Data.SqlClient;
namespace ConsoleApp8
{
class Program
{
static void Main(string[] args)
{
//连接串,你自己根据实际的改
string connString = @"Data Source=.\sqlserver2014;Initial Catalog=MvcDemo;User ID=dev";
string[] items = { "0","1","2","3","4","5","6","7" };
string sql = "insert into AAA(InputDate,Xuhao,miaoshu,jieguo) VALUES(@InputDate, @Xuhao, @miaoshu, @jieguo)";
SqlParameter[] spArr = new SqlParameter[]
{
new SqlParameter("@InputDate", DateTime.Now),
new SqlParameter("@Xuhao", items[1]),
new SqlParameter("@Xuhao", items[3]),
new SqlParameter("@Xuhao", items[5]),
};
try
{
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddRange(spArr);
cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.Read();
}
}
}