To insert the row values from data grid view to the table in sql server through vb.ne

chidumca

Member
Joined
Mar 23, 2010
Messages
10
Programming Experience
Beginner
Hi to all,

In my form,i want add the row values of the datagrid view to table.I have three rows & 9 columns.....

kindly provide solution tomy question.....
 
I would suggest creating a DataTable to begin with and binding that to the grid. You can then use a DataAdapter to save the contents of the DataTable to a database at any time.
 
Index out range of exception was caught

hi friends,
when i run my application am getting this error
"Index out of range exception was caught"
"There is no row at position 0."
here is the code
VB.NET:
Dim DBConn As New SqlConnection("Server=192.168.1.2;User ID=sa;Password=Tespa01;DataBase=TespaMechanical")
Dim DBCmd As New SqlCommand
Dim DBAdap As New SqlDataAdapter
Dim DS As New DataSet
Dim tbl As DataTable
Dim dr As DataRow
Dim st As String = "Leverdial"
Dim i As Integer
Dim strsql As String = "SELECT CustName,WINo,DateofCalib,CustomerRef,OurRef,CalibOnReceipt,UUTName,Make,reqby,IDRef,Description,Temperature,Humidity,Calibby,Remarks1,slno,traceability,range,leastcount,datathrough,expunc,kfactor FROM TI_Calibdata where UniqueID=' " & selectedid & " ' and CalibInstrumentType='" & st & "'"
DBConn.Open()

Try
    DBCmd = New SqlCommand(strsql, DBConn)
    DBCmd.ExecuteNonQuery()
    DBAdap = New SqlClient.SqlDataAdapter(strsql, DBConn)
    DBAdap.Fill(DS)
    tbl = DS.Tables("TI_Calibdata")
    dr = DS.Tables(0).Rows(0)
    ComboBox15.Text = dr.Item("CustName")
    ComboBox1.Text = dr.Item("WINo")
    TextBox1.Text = dr.Item("DateofCalib")
    TextBox2.Text = dr.Item("CustomerRef")
    TextBox18.Text = dr.Item("OurRef")
    ComboBox5.Text = dr.Item("CalibOnReceipt")
    ComboBox3.Text = dr.Item("UUTName")
    ComboBox4.Text = dr.Item("Make")
    ComboBox8.Text = dr.Item("reqby")
    TextBox21.Text = dr.Item("IDRef")
    ComboBox2.Text = dr.Item("Description")
    TextBox6.Text = dr.Item("Temperature")
    TextBox7.Text = dr.Item("Humidity")
    ComboBox6.Text = dr.Item("Calibby")
    TextBox17.Text = dr.Item("Remarks1")
    TextBox4.Text = dr.Item("slno")
    ComboBox16.Text = dr.Item("traceability")
    TextBox3.Text = dr.Item("range")
    TextBox5.Text = dr.Item("leastcount")
    ComboBox7.Text = dr.Item("datathrough")
    TextBox20.Text = dr.Item("expunc")
    TextBox19.Text = dr.Item("kfactor")
Catch exp As Exception
    MsgBox(exp.Message, MsgBoxStyle.Information)
End Try

DBConn.Close()
DBConn = Nothing
pls provide me solution......
:eek:
 
Last edited by a moderator:
You're trying to get data from a DataTable named "TI_Calibdata" but you never populate a DataTable with that name:
VB.NET:
DBAdap.Fill(DS)
The name of the database table is irrelevant. If you want your DataTable to have a name then you have to give it a name:
VB.NET:
DBAdap.Fill(DS, "TI_Calibdata")
 
still it is working .....

Hi,
thanks for suggestion,but still it is not working.I have done the changes which u said

DBAdap.Fill(DS, "TI_Calibdata")
 
Actually, I just noticed that you aren't using the 'tbl' variable anyway. In that case it means that your query isn't returning any data. Have you tested the value returned by Fill? That will tell you how many records the query retrieved. If that's 0 then you've found your problem.
 
i have checked the fill ,it is returning the records in the table....

Hi,
I have checked the fill,it is returning the table values.can u provide any other solutions....
 
Back
Top