bshaen Posted March 26, 2005 Posted March 26, 2005 i would like to update my dataset record, but i dunno what the mistake i made, it cant display the output i want. can anyone point out the mistake for me , thank Dim display As String Dim ds As DataSet = New DataSet Dim myconnection as SqlConnection display = "SELECT * FROM Student WHERE Stdcode='ST01'" Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(display, myconnection) myDataAdapter.Fill(ds, "Student") Quote
cyclonebri Posted March 31, 2005 Posted March 31, 2005 i would like to update my dataset record, but i dunno what the mistake i made, it cant display the output i want. can anyone point out the mistake for me , thank Dim display As String Dim ds As DataSet = New DataSet Dim myconnection as SqlConnection display = "SELECT * FROM Student WHERE Stdcode='ST01'" Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(display, myconnection) myDataAdapter.Fill(ds, "Student") For one, you didn't open your connection or new the connection object, but you may have left that code elsewhere other than this post? Are you getting any errors? Use a Try/Catch block to catch your exceptions. Also, your data adapter code is not going to work either. Check this out, substitute in what you need: Sub TestDotNetCode() 'Dim display As String 'Dim ds As DataSet = New DataSet 'Dim myconnection As SqlConnection 'display = "SELECT * FROM Student WHERE Stdcode='ST01'" 'Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(display, myconnection) 'myDataAdapter.Fill(ds, "Student") Dim constr As String = "ConnectionStringDetailsGoHERE" Dim sql As String = "SELECT * FROM Student WHERE Stdcode='ST01'" Dim cn1 As New SqlClient.SqlConnection(constr) Try cn1.Open() Dim cmd1 As New SqlClient.SqlCommand cmd1.Connection = cn1 cmd1.CommandText = sql cmd1.CommandType = CommandType.Text Dim da1 As New SqlClient.SqlDataAdapter(cmd1) Dim ds1 As New DataSet("Results") da1.Fill(ds1) 'see if dataset exists If IsNothing(ds1) Then MessageBox.Show("Dataset does not exist") Exit Sub End If 'See if any data exists in the dataset: If ds1.Tables.Count = 0 Then MessageBox.Show("NO DATA FOUND!") Else 'make sure that item has data before trying to retrieve it: If Not IsDBNull(ds1.Tables(0).Rows(0).Item(0)) Then MessageBox.Show("DATA SAMPLE: " + ds1.Tables(0).Rows(0).Item(0).ToString()) End If End If Catch ex As Exception 'report errors: MessageBox.Show(ex.ToString()) Finally 'close connection if it exists: If Not IsNothing(cn1) Then If Not cn1.State = ConnectionState.Closed Then cn1.Close() End If End If End Try End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.