這是我的代碼:C#錯誤:「填寫:SelectCommand.Connection屬性尚未初始化。」只是在PC上
SqlDataAdapter adapter = new SqlDataAdapter(query, conn);
該程序正在所有其他電腦除了一個我我得到了這個錯誤:
System.InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized.
at System.Data.Common.DbDataAdapter.GetConnection3(DbDataAdapter adapter, IDbCommand command, String method)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at service_managment.V.Fill_data_set(String query)
at service_managment.V.get_first_of_tabel(String query)
at service_managment.login.button1_Click(Object sender, EventArgs e)
at service_managment.login.tbx_password_KeyDown(Object sender, KeyEventArgs e)
at System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.TextBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
我該如何解決它?
你是否在調用'new SqlDataAdapter(query,conn)'之前初始化'conn'? –
您能否請您發佈完整的代碼以便我們理解問題? – Khan
你沒有將*連接*分配給你的*命令*對象。發佈完整的代碼以指出問題。 – Zeeshan