DataSet ds = new DataSet();
SqlDataAdapter cmd = new SqlDataAdapter("Select * FROM event", con);
cmd.Fill(ds, "Table");
一次又一次地得到同样的错误尝试了一切
请帮忙
DataSet ds = new DataSet();
SqlDataAdapter cmd = new SqlDataAdapter("Select * FROM event", con);
cmd.Fill(ds, "Table");
一次又一次地得到同样的错误尝试了一切
请帮忙
编辑
像这样尝试,其中缺少的元素可能是在下面的代码中添加的命令类型,并且还为数据库打开连接
SqlConnection sqlcon;
using(sqlcon = new SqlConnection("Data Source=Servername;Initial
Catalog=Marketing;Integrated Security=SSPI"))
{
SqlCommand cmd = new SqlCommand("Select * FROM event", sqlcon);
cmd.CommandType = CommandType.Text;
sqlcon.Open();
da = new SqlDataAdapter(sqlcmd);
da.Fill(dt);
}
注意:在 using 语句中使用然后处理所有内容。这也是在上面添加的
在调用填充方法之前执行此操作
SqlConnection conn= new
SqlConnection("Data Source=Servername;Initial Catalog=Marketing;Integrated Security=SSPI");
SqlDataAdapter cmd = new SqlDataAdapter("Select * FROM event", con);
cmd.Fill(ds, "Table");
SqlConnection myconn = new SqlConnection(YourConnString);
SqlCommand mycmd = new SqlCommand();
try{ myconn.Open(); }
catch (Exception ex) { MessageBox("Error");}
mycmd.Connection = myconn;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
String sqlStr = "Select * FROM event";
SqlDataAdapter da = new SqlDataAdapter(sqlStr, myconn);
da.Fill(ds);
dt = ds.Tables[0];