在SQL server northwind建立表Test
cola varchar 50
colb uniqueidentifier 16
页面文件中:
string str;
str = @"server=localhost;uid=sa;pwd=sa;database=northwind";
SqlConnection cn = new SqlConnection(str);
str = "INSERT INTO Test(cola, colb) Values (@a, @b)";
SqlCommand cmd = new SqlCommand(str, cn);
cmd.Parameters.Add("@a",SqlDbType.VarChar).Value = "aa";
cmd.Parameters.Add("@b",SqlDbType.UniqueIdentifier).Value = new Guid(System.Guid.NewGuid().ToString());
cn.Open();
int i = cmd.ExecuteNonQuery();
if (i != 0)
Response.Write ("操作查询已执行");
cn.Close();
cola varchar 50
colb uniqueidentifier 16
页面文件中:
string str;
str = @"server=localhost;uid=sa;pwd=sa;database=northwind";
SqlConnection cn = new SqlConnection(str);
str = "INSERT INTO Test(cola, colb) Values (@a, @b)";
SqlCommand cmd = new SqlCommand(str, cn);
cmd.Parameters.Add("@a",SqlDbType.VarChar).Value = "aa";
cmd.Parameters.Add("@b",SqlDbType.UniqueIdentifier).Value = new Guid(System.Guid.NewGuid().ToString());
cn.Open();
int i = cmd.ExecuteNonQuery();
if (i != 0)
Response.Write ("操作查询已执行");
cn.Close();