开发者

Transfer data in a ListBox to SQL database

I using Visual Studio 2010.My problem is; I can not transfer all data in a listbox to SQL Database. codes are as follows.

    Dim builder As SqlClient.SqlCommandBuilder = New  SqlC开发者_JAVA技巧lient.SqlCommandBuilder(adaptor4)
    Dim insert_komut As New SqlClient.SqlCommand
    datakayit4 = kayit4.Tables("aaaaa").NewRow

    Dim i As Integer

    For i = 1 To ListBox5.Items.Count

        datakayit4("m_fabricno") = ListBox5.Items.Item(i)

    Next

    kayit4.Tables("bakimkaydi").Rows.Add(datakayit4)
    adaptor4.Update(kayit4, "aaaaa") 

How can get rid of this problem ?

Thanks in advance .


Your code only adds one row to the table.

You need to add rows inside the loop.
This way, you can add multiple rows to the table.


Try this. Your code is replacing the same row over and over in the loop, you need to add the row for each item in the listbox

Dim builder As SqlClient.SqlCommandBuilder = New  SqlClient.SqlCommandBuilder(adaptor4)
    Dim insert_komut As New SqlClient.SqlCommand

    Dim i As Integer

    For i = 1 To ListBox5.Items.Count
        datakayit4 = kayit4.Tables("aaaaa").NewRow
        datakayit4("m_fabricno") = ListBox5.Items.Item(i)
        kayit4.Tables("bakimkaydi").Rows.Add(datakayit4)
        adaptor4.Update(kayit4, "aaaaa") 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜