|
-
Apr 3rd, 2008, 06:34 PM
#1
Thread Starter
Lively Member
[2005] datagridview just insert 1row: s
i have 2 textboxes,1 gridview, 1button
i put some text into the textboxes then i press the button, i can get 1 row....but when i repeat the proccess replaces the last row whith new values...always just have 1 row in my grid...
i want more then 1 row, if i press the button 5 times e want 5 rows
any help???
sorry for my english
inside the button i have this code
Code:
'Criando o Dataset
Dim dsFornecedor As New DataSet()
'Criando a tabela
Dim tblFornecedores As New DataTable()
dsFornecedor.Tables.Add(tblFornecedores)
'Estrutura do DataTable
tblFornecedores.Columns.Add("CodFornecedor")
tblFornecedores.Columns.Add("NomeFornecedor")
'Criando Registros
Dim row As DataRow = tblFornecedores.NewRow()
row("CodFornecedor") = TextBox1.Text
row("NomeFornecedor") = TextBox2.Text
tblFornecedores.Rows.Add(row)
DataGridView1.DataSource = dsFornecedor.Tables(0)
Did a reply help answer your questions? Please rate good posts!
-
Apr 3rd, 2008, 06:47 PM
#2
Re: [2005] datagridview just insert 1row: s
That's because you are creating a completely new DataSet and DataTable each time. You are discarding the one that contains the previous row so you lose all the old data. You should creating one DataTable only and binding that to the grid in the beginning. You then add a new row to THAT DataTable each time.
-
Apr 3rd, 2008, 06:58 PM
#3
Thread Starter
Lively Member
Re: [2005] datagridview just insert 1row: s
Please can you show me some example?? im newbie i dont now how to what you said...thanksss
Did a reply help answer your questions? Please rate good posts!
-
Apr 3rd, 2008, 07:55 PM
#4
Re: [2005] datagridview just insert 1row: s
Yes you do, because you're already doing it. You're already creating a DataTable and adding a row to it, and that's all you need to do. The change you need to make is to take the part that creates the DataTable OUT of the code that gets called over and over again and put it somewhere that it will only be executed once, like the load event handler of the form. That way you create one table and one table only, then each time you create a new row you add it to that same table.
-
Apr 3rd, 2008, 08:14 PM
#5
Thread Starter
Lively Member
Re: [2005] datagridview just insert 1row: s
thanksss ... i done what you said and it worksssssss .. now i have 5...30...50... rowsss
Did a reply help answer your questions? Please rate good posts!
-
Apr 3rd, 2008, 10:08 PM
#6
Re: [2005] datagridview just insert 1row: s
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|