udir
asked on
ADO.NET and DataGridView....
Hi,
I wrote:
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=(local);initial catalog=Mashavit;integrate d
security=sspi";
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from tblCandidPhases", con);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridPhase.DataSource = dt;
when i update the fields in the DataGridView or when i add/delete rows, nothing happaned in the table - 'tblCandidPhases' (a table in sqlServer)
why?? what's wrong?
Thanks
(Sorry about the small points - it's all i'v got)
I wrote:
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=(local);initial catalog=Mashavit;integrate
security=sspi";
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from tblCandidPhases", con);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridPhase.DataSource = dt;
when i update the fields in the DataGridView or when i add/delete rows, nothing happaned in the table - 'tblCandidPhases' (a table in sqlServer)
why?? what's wrong?
Thanks
(Sorry about the small points - it's all i'v got)
ASKER
Hi Ahmad,
Thanks again for the reply :)
Did you ment - 'sqlCommandBuilder' ?
(why OleDbCommandBuilder - i get an error massages).
and if i use the 'sqlCommandBuilder' steel.... nothing happaned.
Thanks
Thanks again for the reply :)
Did you ment - 'sqlCommandBuilder' ?
(why OleDbCommandBuilder - i get an error massages).
and if i use the 'sqlCommandBuilder' steel.... nothing happaned.
Thanks
OOPS!! it's Sql not OleDb .. it's a typo ;o)
take care ..
take care ..
ASKER
Hi,
nothing happaned in the table, why?
the code is :
private void dataGridPhase_CurrentCellC hanged(obj ect sender, System.EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=(local);initial catalog=Mashavit;integrate d security=sspi";
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from tblCandidPhases", con);
DataTable dt = new DataTable();
da.Fill(dt);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(dt);
}
nothing happaned in the table, why?
the code is :
private void dataGridPhase_CurrentCellC
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=(local);initial catalog=Mashavit;integrate
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from tblCandidPhases", con);
DataTable dt = new DataTable();
da.Fill(dt);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(dt);
}
I stated that CurrentCellChanged event is for updating the database ..
not filling th dataset ..!!
private void dataGridPhase_CurrentCellC hanged(obj ect sender, System.EventArgs e)
{
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(dt);
}
not filling th dataset ..!!
private void dataGridPhase_CurrentCellC
{
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(dt);
}
May be you'll get an Error Messages stated that *da* and *dt* object does not exist or something like that ..
so be sure to declare both of them in the class scope not in a method scope ..
regards,Ahmad;
so be sure to declare both of them in the class scope not in a method scope ..
regards,Ahmad;
ASKER
Ahmad, sorry for being annoying but there is somthing basic that i don't
understand:
If i write only the code you wrote:
private void dataGridPhase_CurrentCellC hanged(obj ect sender, System.EventArgs e)
{
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(dt);
}
Where do i put the lines :
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=(local);initial catalog=Mashavit;integrate d security=sspi";
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from tblCandidPhases", con);
DataTable dt = new DataTable();
da.Fill(dt);
How 'da' and 'dt' will be recognized in the event if thay were not created in the Event? (in your code)
Again, sorry for that.....
understand:
If i write only the code you wrote:
private void dataGridPhase_CurrentCellC
{
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(dt);
}
Where do i put the lines :
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=(local);initial catalog=Mashavit;integrate
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from tblCandidPhases", con);
DataTable dt = new DataTable();
da.Fill(dt);
How 'da' and 'dt' will be recognized in the event if thay were not created in the Event? (in your code)
Again, sorry for that.....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'll go offline now ;o)
I'll be back tommorrow morning ..
regards,Ahmad;
I'll be back tommorrow morning ..
regards,Ahmad;
ASKER
OK
Thanks
Thanks
ASKER
Ahmad, points are yours anyway, thanks
i will be most greatfull if you could show me what to write
in the class scope and where - do you meen to write a function or what?
(as you see i'm a bigginer in C# and in OOP so not everything is so clear to me).
Thanks
i will be most greatfull if you could show me what to write
in the class scope and where - do you meen to write a function or what?
(as you see i'm a bigginer in C# and in OOP so not everything is so clear to me).
Thanks
I'll give you example ..
public class form1 : System.Windows.Forms.Form
{
// Whatever here
SqlDataAdapter da; // it is declared in the class scope
DataTable dt = new DataTable();
private void Form1_Load(object sender, System.EventArgs e)
{ // this is a method scope
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=(local);initial catalog=Mashavit;integrate d security=sspi";
con.Open();
da = new SqlDataAdapter("select * from tblCandidPhases", con);
da.Fill(dt);
// add codes to bind the datatable to the datagrid ..
}
// another methods as neeeded ..
private void dataGridPhase_CurrentCellC hanged(obj ect sender, System.EventArgs e)
{ // because da and dt is declared in the class scope .. it will compile and work fine ..
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(dt);
}
}
regards,Ahmad;
public class form1 : System.Windows.Forms.Form
{
// Whatever here
SqlDataAdapter da; // it is declared in the class scope
DataTable dt = new DataTable();
private void Form1_Load(object sender, System.EventArgs e)
{ // this is a method scope
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=(local);initial catalog=Mashavit;integrate
con.Open();
da = new SqlDataAdapter("select * from tblCandidPhases", con);
da.Fill(dt);
// add codes to bind the datatable to the datagrid ..
}
// another methods as neeeded ..
private void dataGridPhase_CurrentCellC
{ // because da and dt is declared in the class scope .. it will compile and work fine ..
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(dt);
}
}
regards,Ahmad;
ASKER
Thanks Alot!!!!
private void dataGridPhase_CurrentCellC
{
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
da.Update(dt);
}
regards,Ahmad;