compman_74
New member
- Joined
- Oct 26, 2009
- Messages
- 1
- Programming Experience
- Beginner
I am new at programming in VB and I am tackling a medium size project for my first program. At this point what I am trying to do is fill a datagridview with a row from an sql table. I believe that I have the proper coding in place and I am able to connect to the sql server. I just cannot get the information to populate to the datagridview. I am including my code snippet which I am trying to use to accomplish this task. Please any comments on how things can be done better is appreicated.
Code:
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim dr As New SqlDataAdapter()
Dim table As New DataTable
'Dim sqltext As String
conn = New SqlConnection("server=.\sqlexpress,uid=sa,pwd=!!InDian##,database=ipcs_cb_line")
Try
conn.Open()
cmd = New SqlCommand("select [ModelNo],[Phase],[Votage],[MinCircuitAmps], [MaxCircuitAmps],[Frequency],[Compressorized],[CompQTY],[CompHP]" & _
",[CompVAC],[CompPH],[CompRPM],[CompFLA],[CompRLA],[CompLRA],[CondQTY],[CondHP],[CondVAC],[CondPH],[CondRPM],[CondFLA],[CondRLA]" & _
",[CondLRA],[Front],[LeftSide],[RightSide],[Back],[C1Oz],[C2Oz],[C3Oz],[C4Oz],[RefrigType],[TagNum]" & _
"From [IPCS_CB_LINE].[dbo].[Rating_Plate_Info] where [ModelNo]=@ModelNo")
dr = cmd.ExecuteNonQuery
dr.SelectCommand.Parameters.Add("@modelno", SqlDbType.NVarChar, 50).Value = search.Text
dr.Fill(table)
DataView.DataSource = table.DefaultView
conn.Close()
Catch ex As Exception
End Try
Code:
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim dr As New SqlDataAdapter()
Dim table As New DataTable
'Dim sqltext As String
conn = New SqlConnection("server=.\sqlexpress,uid=sa,pwd=!!InDian##,database=ipcs_cb_line")
Try
conn.Open()
cmd = New SqlCommand("select [ModelNo],[Phase],[Votage],[MinCircuitAmps], [MaxCircuitAmps],[Frequency],[Compressorized],[CompQTY],[CompHP]" & _
",[CompVAC],[CompPH],[CompRPM],[CompFLA],[CompRLA],[CompLRA],[CondQTY],[CondHP],[CondVAC],[CondPH],[CondRPM],[CondFLA],[CondRLA]" & _
",[CondLRA],[Front],[LeftSide],[RightSide],[Back],[C1Oz],[C2Oz],[C3Oz],[C4Oz],[RefrigType],[TagNum]" & _
"From [IPCS_CB_LINE].[dbo].[Rating_Plate_Info] where [ModelNo]=@ModelNo")
dr = cmd.ExecuteNonQuery
dr.SelectCommand.Parameters.Add("@modelno", SqlDbType.NVarChar, 50).Value = search.Text
dr.Fill(table)
DataView.DataSource = table.DefaultView
conn.Close()
Catch ex As Exception
End Try