The ConnectionString property has not been initialized !
-
Hi Everybody ! in btnShow_Click() :
try { string query="Select * from TestReport"; con.Open(); da=new SqlDataAdapter(query,con); sqlcmb=new SqlCommandBuilder(da); da.Fill(DS,"TestReport"); dt = DS.Tables["TestReport"]; dv = dt.DefaultView; dataGrid1.DataSource=dv; con.Close(); sqlcmb.Dispose(); con.Dispose(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } }
at the first I have no problem for showing records , but at the second when I press th Show Button , I have this error : The ConnectionString property has not been initialized ! thanx for any help ! Regards ,s_mostafa_h
-
Hi Everybody ! in btnShow_Click() :
try { string query="Select * from TestReport"; con.Open(); da=new SqlDataAdapter(query,con); sqlcmb=new SqlCommandBuilder(da); da.Fill(DS,"TestReport"); dt = DS.Tables["TestReport"]; dv = dt.DefaultView; dataGrid1.DataSource=dv; con.Close(); sqlcmb.Dispose(); con.Dispose(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } }
at the first I have no problem for showing records , but at the second when I press th Show Button , I have this error : The ConnectionString property has not been initialized ! thanx for any help ! Regards ,s_mostafa_h
Hello Your problem is in this line:
con.Dispose();
You shouldn't dispose the connection if you'll use it again. also I don't recommend opening/closing the connection each time you make a query. Regards:rose:
-
Hello Your problem is in this line:
con.Dispose();
You shouldn't dispose the connection if you'll use it again. also I don't recommend opening/closing the connection each time you make a query. Regards:rose:
-
hi there , but , if it does'nt Dispose() , eachtime , I press the button , all previous records is added again to the end of record . thanx a lot ,
s_mostafa_h
-
Hi Everybody ! in btnShow_Click() :
try { string query="Select * from TestReport"; con.Open(); da=new SqlDataAdapter(query,con); sqlcmb=new SqlCommandBuilder(da); da.Fill(DS,"TestReport"); dt = DS.Tables["TestReport"]; dv = dt.DefaultView; dataGrid1.DataSource=dv; con.Close(); sqlcmb.Dispose(); con.Dispose(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } }
at the first I have no problem for showing records , but at the second when I press th Show Button , I have this error : The ConnectionString property has not been initialized ! thanx for any help ! Regards ,s_mostafa_h
-
hi there , but , if it does'nt Dispose() , eachtime , I press the button , all previous records is added again to the end of record . thanx a lot ,
s_mostafa_h
Hello You shouldn't dispose your connection until you don't need it anymore in the current session. If you want to clear you DataGridView -as I understood from your reply-, then you should call the
DataGridView.Rows.Clear()
method before filling it again. Regards:rose: -
Hello You shouldn't dispose your connection until you don't need it anymore in the current session. If you want to clear you DataGridView -as I understood from your reply-, then you should call the
DataGridView.Rows.Clear()
method before filling it again. Regards:rose:Nader Elshehabi wrote:
You shouldn't dispose your connection until you don't need it anymore in the current session. If you want to clear you DataGridView -as I understood from your reply-, then you should call the DataGridView.Rows.Clear() method before filling it again.
This is what I was getting at - sorry for the lack of detail.