c#select语句添加记录哪里出错了

来源:百度知道 编辑:UC知道 时间:2024/06/20 08:05:29
public void GetConnect(string sqlstr)
{
try
{
string connectstring = "server=localhost;database=wish";
SqlConnection conn = new SqlConnection(connectstring);
SqlCommand comm = conn.CreateCommand();
conn.Open();
comm.Connection = conn;
comm.CommandText = sqlstr;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
C1.GetConnect("insert into wishtext11 values( 'jdfaf ','2008-9-20','10000',' 游侠 ')");

首先数据库链接错误
connectstring = "server=localhost;database=wish;uid=用户名;pwd=密码";

其次Insert语句

应该如下

C1.GetConnect("insert into wishtext11(这里应该填写对应的字段列表) values( 'jdfaf ','2008-9-20','10000',' 游侠 ')");

比如
C1.GetConnect("insert into wishtext11(用户名,日期,积分,等级) values( 'jdfaf ','2008-9-20','10000',' 游侠 ')");

查询语句的字段名没有写~~
C1.GetConnect("insert into wishtext11 (xx,xx,xx,xx) values( 'jdfaf ','2008-9-20','10000',' 游侠 ')");
XX位置写入你相关的数据库字段名称

连接字符串要用户名和密码的