ERROR in ds.Tables.Item("SampleID").ToString() [modified]
-
Just disregard this issue. I already solved it guys. Hi Guys, Can you help me if what's wrong with my source code? I am using ASP.Net 2.0 and I got an error in "MsgBox(ds.Tables.Item("SampleID").ToString())" Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim strConnString As String = ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString Dim sqlConn As New Data.SqlClient.SqlConnection(strConnString) Dim cmd As New Data.SqlClient.SqlCommand Dim da As Data.SqlClient.SqlDataAdapter Dim ds As New Data.DataSet cmd.CommandText = "select SampleID, RowID from tblSample where SampleID = 100" cmd.CommandType = CommandType.Text cmd.Connection = sqlConn da = New Data.SqlClient.SqlDataAdapter(cmd) da.Fill(ds) MsgBox(ds.Tables.Item("SampleID").ToString()) MsgBox(ds.Tables.Item(0).Rows(0).Item(1).ToString()) da.Dispose() ds.Dispose() sqlConn.Close() -- modified at 10:03 Saturday 9th June, 2007
hifiger2004
-
Just disregard this issue. I already solved it guys. Hi Guys, Can you help me if what's wrong with my source code? I am using ASP.Net 2.0 and I got an error in "MsgBox(ds.Tables.Item("SampleID").ToString())" Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim strConnString As String = ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString Dim sqlConn As New Data.SqlClient.SqlConnection(strConnString) Dim cmd As New Data.SqlClient.SqlCommand Dim da As Data.SqlClient.SqlDataAdapter Dim ds As New Data.DataSet cmd.CommandText = "select SampleID, RowID from tblSample where SampleID = 100" cmd.CommandType = CommandType.Text cmd.Connection = sqlConn da = New Data.SqlClient.SqlDataAdapter(cmd) da.Fill(ds) MsgBox(ds.Tables.Item("SampleID").ToString()) MsgBox(ds.Tables.Item(0).Rows(0).Item(1).ToString()) da.Dispose() ds.Dispose() sqlConn.Close() -- modified at 10:03 Saturday 9th June, 2007
hifiger2004
For anyone else searching wondering what's wrong, this is server side code, you can't display message boxes that will be visible in the browser. Try writing the field contents to the web page you are creating:
Response.Write(ds.Tables.Item("SampleID").ToString())