my code listed below shows an error on running web page
error message on da1.fill(dt1) says : Fill: SelectCommand.Connection property has not been initialized.
how can i manage to solve this issue while using 2 different dataset and datafill on one connection or 2 different connections .. i tried both but didnt work
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conn As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString1").ToString)
Dim cmd As New SqlClient.SqlCommand
Dim id As String = ""
Dim thb1 As String = ""
Dim thb2 As String = ""
Dim thb3 As String = ""
Dim thb4 As String = ""
Dim lk As String = ""
Dim u1 As String = ""
Dim U2 As String = ""
Dim U3 As String = ""
Dim U4 As String = ""
cmd.CommandText = "sp_carosel1"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@id", id.ToString)
cmd.Parameters.AddWithValue("@projtitle", ttllbl1.Text)
cmd.Parameters.AddWithValue("@projtext", txtlbl1.Text)
cmd.Parameters.AddWithValue("@thumb", thb1.ToString)
cmd.Parameters.AddWithValue("lnk", lk)
cmd.Connection = conn
cmd.Connection.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter
Dim dt As New DataTable
da.SelectCommand = cmd
da.Fill(dt)
If dt.Rows.Count > 0 Then
ttllbl1.Text = dt.Rows(0)("projtitle").ToString()
txtlbl1.Text = dt.Rows(0)("projtext").ToString
thb1 = dt.Rows(0)("thumb").ToString
u1 = dt.Rows(0)("projtitle").ToString
Image1.ImageUrl = "images\projects\" + u1 + "\" + thb1
ttllbl2.Text = dt.Rows(1)("projtitle").ToString()
txtlbl2.Text = dt.Rows(1)("projtext").ToString
thb2 = dt.Rows(1)("thumb").ToString
u1 = dt.Rows(1)("projtitle").ToString
Image2.ImageUrl = "images\projects\" + U2 + "\" + thb2
ttllbl3.Text = dt.Rows(2)("projtitle").ToString()
txtlbl3.Text = dt.Rows(2)("projtext").ToString
thb3 = dt.Rows(2)("thumb").ToString
U3 = dt.Rows(2)("projtitle").ToString
Image3.ImageUrl = "images\projects\" + U3 + "\" + thb3
ttllbl4.Text = dt.Rows(3)("projtitle").ToString()
txtlbl4.Text = dt.Rows(3)("projtext").ToString
thb4 = dt.Rows(3)("thumb").ToString
U4 = dt.Rows(3)("projtitle").ToString
Image4.ImageUrl = "images\projects\" + U4 + "\" + thb4
End If
'cmd.ExecuteNonQuery()
'cmd.Connection.Close()
''//////////////////////////// abt company / abt services / abt projects
'Dim con As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString1").ToString)
Dim cmd2 As New SqlClient.SqlCommand
cmd2.CommandText = "indexsp"
cmd2.CommandType = CommandType.StoredProcedure
cmd2.Parameters.AddWithValue("@aboutus", abtcolbl.Text)
cmd2.Parameters.AddWithValue("@abtservices", abtserviceslbl.Text)
cmd2.Parameters.AddWithValue("@abtprji", abtprojlbl.Text)
'conn.Open()
Dim da1 As SqlDataAdapter = New SqlDataAdapter
Dim dt1 As New DataTable
da1.SelectCommand = cmd2
da1.Fill(dt1)
If dt1.Rows.Count > 0 Then
abtserviceslbl.Text = dt1.Rows(0)("abtservices").ToString()
abtprojlbl.Text = dt1.Rows(0)("abtprji").ToString
abtcolbl.Text = dt1.Rows(0)("aboutus").ToString
End If
cmd2.ExecuteNonQuery()
conn.Close()
thanks in advance :)
You're not showing the correct code. According the error, you have another data adapter (da1) that you're using that doesn't have a .SelectCommand property set.
in reality this is the rewal code, i resolved this issue as i modified the variable that recieves the session from dim to public .. and that is working great
Marked as answer by ali.alakhdar on Mar 02, 2012 10:01 AM
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
ali.alakhdar
Member
168 Points
83 Posts
Fill: SelectCommand.Connection property has not been initialized
Mar 01, 2012 03:35 PM|LINK
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim conn As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString1").ToString) Dim cmd As New SqlClient.SqlCommand Dim id As String = "" Dim thb1 As String = "" Dim thb2 As String = "" Dim thb3 As String = "" Dim thb4 As String = "" Dim lk As String = "" Dim u1 As String = "" Dim U2 As String = "" Dim U3 As String = "" Dim U4 As String = "" cmd.CommandText = "sp_carosel1" cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@id", id.ToString) cmd.Parameters.AddWithValue("@projtitle", ttllbl1.Text) cmd.Parameters.AddWithValue("@projtext", txtlbl1.Text) cmd.Parameters.AddWithValue("@thumb", thb1.ToString) cmd.Parameters.AddWithValue("lnk", lk) cmd.Connection = conn cmd.Connection.Open() Dim da As SqlDataAdapter = New SqlDataAdapter Dim dt As New DataTable da.SelectCommand = cmd da.Fill(dt) If dt.Rows.Count > 0 Then ttllbl1.Text = dt.Rows(0)("projtitle").ToString() txtlbl1.Text = dt.Rows(0)("projtext").ToString thb1 = dt.Rows(0)("thumb").ToString u1 = dt.Rows(0)("projtitle").ToString Image1.ImageUrl = "images\projects\" + u1 + "\" + thb1 ttllbl2.Text = dt.Rows(1)("projtitle").ToString() txtlbl2.Text = dt.Rows(1)("projtext").ToString thb2 = dt.Rows(1)("thumb").ToString u1 = dt.Rows(1)("projtitle").ToString Image2.ImageUrl = "images\projects\" + U2 + "\" + thb2 ttllbl3.Text = dt.Rows(2)("projtitle").ToString() txtlbl3.Text = dt.Rows(2)("projtext").ToString thb3 = dt.Rows(2)("thumb").ToString U3 = dt.Rows(2)("projtitle").ToString Image3.ImageUrl = "images\projects\" + U3 + "\" + thb3 ttllbl4.Text = dt.Rows(3)("projtitle").ToString() txtlbl4.Text = dt.Rows(3)("projtext").ToString thb4 = dt.Rows(3)("thumb").ToString U4 = dt.Rows(3)("projtitle").ToString Image4.ImageUrl = "images\projects\" + U4 + "\" + thb4 End If 'cmd.ExecuteNonQuery() 'cmd.Connection.Close() ''//////////////////////////// abt company / abt services / abt projects 'Dim con As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString1").ToString) Dim cmd2 As New SqlClient.SqlCommand cmd2.CommandText = "indexsp" cmd2.CommandType = CommandType.StoredProcedure cmd2.Parameters.AddWithValue("@aboutus", abtcolbl.Text) cmd2.Parameters.AddWithValue("@abtservices", abtserviceslbl.Text) cmd2.Parameters.AddWithValue("@abtprji", abtprojlbl.Text) 'conn.Open() Dim da1 As SqlDataAdapter = New SqlDataAdapter Dim dt1 As New DataTable da1.SelectCommand = cmd2 da1.Fill(dt1) If dt1.Rows.Count > 0 Then abtserviceslbl.Text = dt1.Rows(0)("abtservices").ToString() abtprojlbl.Text = dt1.Rows(0)("abtprji").ToString abtcolbl.Text = dt1.Rows(0)("aboutus").ToString End If cmd2.ExecuteNonQuery() conn.Close() thanks in advance :)adamturner34
Contributor
4394 Points
1102 Posts
Re: Fill: SelectCommand.Connection property has not been initialized
Mar 01, 2012 04:22 PM|LINK
You're not showing the correct code. According the error, you have another data adapter (da1) that you're using that doesn't have a .SelectCommand property set.
ali.alakhdar
Member
168 Points
83 Posts
Re: Fill: SelectCommand.Connection property has not been initialized
Mar 02, 2012 10:00 AM|LINK
in reality this is the rewal code, i resolved this issue as i modified the variable that recieves the session from dim to public .. and that is working great
superguppie
All-Star
48225 Points
8679 Posts
Re: Fill: SelectCommand.Connection property has not been initialized
Mar 02, 2012 01:00 PM|LINK
You don't set cmd2.Connection to conn.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.