filling a dataGridView, editing and overwriting [modified]
-
Hello everyone I've once asked this question but I thought that I couldn't make it clear. I have a table and I want to view it on my dataGridView. I need to fill this dataGridView by codes, not with the interface. I also allowed the user to edit this dataGridView in the runtime. User can change the values of cells, and also add rows to the table. My two questions are: how can I fill this dataGridView by hardcoding and how can I overwrite the loaded table with the edited table by the user? please please please help and be clear with me in this. I'm pretty rookie and this is the only thing left in my project to finish :( EDIT! Somehow I managed to fill the table, now, only saving left. Please. Anyone? EDIT2 well, I did sth :) I'm filling the table like this:
string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
dbGridView.DataSource = ds.Tables[0];it works, and from the same source, someone says that "you can use 'da.Update(ds);' for updating your table" I want to update the table on some SAVE button, so I wrote this:
private void saveButton_Click(object sender, EventArgs e)
{
string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
da.Update(ds);
this.Close();}
bu "da.Update(ds)" does not update my table in the database where is my mistake?
modified on Tuesday, December 1, 2009 1:06 AM
-
Hello everyone I've once asked this question but I thought that I couldn't make it clear. I have a table and I want to view it on my dataGridView. I need to fill this dataGridView by codes, not with the interface. I also allowed the user to edit this dataGridView in the runtime. User can change the values of cells, and also add rows to the table. My two questions are: how can I fill this dataGridView by hardcoding and how can I overwrite the loaded table with the edited table by the user? please please please help and be clear with me in this. I'm pretty rookie and this is the only thing left in my project to finish :( EDIT! Somehow I managed to fill the table, now, only saving left. Please. Anyone? EDIT2 well, I did sth :) I'm filling the table like this:
string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
dbGridView.DataSource = ds.Tables[0];it works, and from the same source, someone says that "you can use 'da.Update(ds);' for updating your table" I want to update the table on some SAVE button, so I wrote this:
private void saveButton_Click(object sender, EventArgs e)
{
string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
da.Update(ds);
this.Close();}
bu "da.Update(ds)" does not update my table in the database where is my mistake?
modified on Tuesday, December 1, 2009 1:06 AM
-
unfortunately no it only tells how to update the table in a single action. I want to save the whole table at once :/
-
Hello everyone I've once asked this question but I thought that I couldn't make it clear. I have a table and I want to view it on my dataGridView. I need to fill this dataGridView by codes, not with the interface. I also allowed the user to edit this dataGridView in the runtime. User can change the values of cells, and also add rows to the table. My two questions are: how can I fill this dataGridView by hardcoding and how can I overwrite the loaded table with the edited table by the user? please please please help and be clear with me in this. I'm pretty rookie and this is the only thing left in my project to finish :( EDIT! Somehow I managed to fill the table, now, only saving left. Please. Anyone? EDIT2 well, I did sth :) I'm filling the table like this:
string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
dbGridView.DataSource = ds.Tables[0];it works, and from the same source, someone says that "you can use 'da.Update(ds);' for updating your table" I want to update the table on some SAVE button, so I wrote this:
private void saveButton_Click(object sender, EventArgs e)
{
string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
da.Update(ds);
this.Close();}
bu "da.Update(ds)" does not update my table in the database where is my mistake?
modified on Tuesday, December 1, 2009 1:06 AM
if you wanna see the mistake try to put toggle breakpoint in you methods and debogue step by step F10. it's easy to debugue :) :) :zzz:
-
if you wanna see the mistake try to put toggle breakpoint in you methods and debogue step by step F10. it's easy to debugue :) :) :zzz:
of course I did that :D compiler just acts as if it ignores the update method, It tells me as if "executes" the update, but I cannot see any change on DB
-
unfortunately no it only tells how to update the table in a single action. I want to save the whole table at once :/
In the button click, you are again fetching the data from the database. Here, you should be using the dataset you have modified. Then, you have not mentioned any update command for your adapter so it will not know what and where to update. You should: 1. Use the same dataset that you have used to fetch the data 2. Use same adapter as earlier and set its update command. Also, read the description of the SQLDataAdapter.Update method from MSDN. It should be having some sample code that will help you understand.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
-
In the button click, you are again fetching the data from the database. Here, you should be using the dataset you have modified. Then, you have not mentioned any update command for your adapter so it will not know what and where to update. You should: 1. Use the same dataset that you have used to fetch the data 2. Use same adapter as earlier and set its update command. Also, read the description of the SQLDataAdapter.Update method from MSDN. It should be having some sample code that will help you understand.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
oh thank you, I'll have a look =)
-
Hello everyone I've once asked this question but I thought that I couldn't make it clear. I have a table and I want to view it on my dataGridView. I need to fill this dataGridView by codes, not with the interface. I also allowed the user to edit this dataGridView in the runtime. User can change the values of cells, and also add rows to the table. My two questions are: how can I fill this dataGridView by hardcoding and how can I overwrite the loaded table with the edited table by the user? please please please help and be clear with me in this. I'm pretty rookie and this is the only thing left in my project to finish :( EDIT! Somehow I managed to fill the table, now, only saving left. Please. Anyone? EDIT2 well, I did sth :) I'm filling the table like this:
string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
dbGridView.DataSource = ds.Tables[0];it works, and from the same source, someone says that "you can use 'da.Update(ds);' for updating your table" I want to update the table on some SAVE button, so I wrote this:
private void saveButton_Click(object sender, EventArgs e)
{
string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
da.Update(ds);
this.Close();}
bu "da.Update(ds)" does not update my table in the database where is my mistake?
modified on Tuesday, December 1, 2009 1:06 AM
what is the SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);????? it's SqlDataAdapter not SqlCeDataAdapter!!! and SqlCommandBuilder not SqlCeCommandBuilder !!!:confused:
-
what is the SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);????? it's SqlDataAdapter not SqlCeDataAdapter!!! and SqlCommandBuilder not SqlCeCommandBuilder !!!:confused:
they are SQL Compact Edition commands :D