DataSet ds = new DataSet();
SqlDataAdapter cmd = new SqlDataAdapter("Select * FROM event", con);
cmd.Fill(ds, "Table");
再次得到同樣的錯誤,並試圖再次一切錯誤顯示出來填充:SelectCommand.Connection屬性尚未初始化
請幫助
DataSet ds = new DataSet();
SqlDataAdapter cmd = new SqlDataAdapter("Select * FROM event", con);
cmd.Fill(ds, "Table");
再次得到同樣的錯誤,並試圖再次一切錯誤顯示出來填充:SelectCommand.Connection屬性尚未初始化
請幫助
編輯
嘗試這樣的,缺少元素在這可能是命令類型,它被添加在下面的代碼中,也打開連接數據庫
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);
}
注意:使用然後處理所有使用語句。這也被添加上述
調用補法
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];
和'con'被初始化爲之前做到這一點? –
SqlConnection con; con = new SqlConnection(「Data Source = 192.168.0.97; Integrated Security = True」); con.Open(); – vini
檢查我編輯的答案,並做這樣的事情必須解決您的問題...在這可能缺少的元素可能是命令類型 –