using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
public partial class Content : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int _Id = Convert.ToInt32(Request.QueryString["Id"]);
int _NewsDetails = Convert.ToInt32(Request.QueryString["NewsDetails"]);
int _NewsId = Convert.ToInt32(Request.QueryString["NewsId"]);
//open your database connection
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\MySite\\Pandheri\\App_Data\\Padheri.mdf;Integrated Security=True;User Instance=True");
SqlCommand _cmd = new SqlCommand ("Select * From ArticleTable where [Id]=" + _Id + " AND [NewsDetails]=" + _NewsDetails + " AND [NewsId]=" + _NewsId);
DataSet ds = new DataSet();
SqlDataAdapter adptr = new SqlDataAdapter(_cmd);
adptr.Fill(ds);
//close your database connection
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
}
I am unable to solve this since last 1 week.
Error:::
Fill: SelectCommand.Connection property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized.
Source Error:
Line 25: DataSet ds = new DataSet();
Line 26: SqlDataAdapter adptr = new SqlDataAdapter(_cmd);
Line 27: adptr.Fill(ds,"NewsDetails");
Line 28: //close your database connection
Line 29: Repeater1.DataSource = ds;
Fill: SelectCommand.Connection property has not been initialized.
Description: An
unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized.
Source Error:
Line 26: DataSet ds = new DataSet();
Line 27: SqlDataAdapter adptr = new SqlDataAdapter(_cmd);
Line 28: adptr.Fill(ds); Line 29: //close your database connection
Line 30:
Description: An
error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1502: The best overloaded method match for 'System.Data.SqlClient.SqlDataAdapter.SqlDataAdapter(string, string)' has some invalid arguments
Source Error:
Line 25: SqlCommand _cmd = new SqlCommand ("Select * From ArticleTable where [Id]=" + _Id + " AND [NewsDetails]=" + _NewsDetails + " AND [NewsId]=" + _NewsId,conn);
Line 26: DataSet ds = new DataSet();
Line 27: SqlDataAdapter adptr = new SqlDataAdapter(_cmd,conn); Line 28: adptr.Fill(ds);
Line 29: //close your database connection
CS1502: The best overloaded method match for 'System.Data.SqlClient.SqlDataAdapter.SqlDataAdapter(string, string)' has some invalid arguments
content.aspx.cs file
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
public partial class Content : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int _Id = Convert.ToInt32(Request.QueryString["Id"]);
int _NewsDetails = Convert.ToInt32(Request.QueryString["NewsDetails"]);
int _NewsId = Convert.ToInt32(Request.QueryString["NewsId"]);
//open your database connection
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\MySite\\Pandheri\\App_Data\\Padheri.mdf;Integrated Security=True;User Instance=True");
conn.Open();
SqlCommand _cmd = new SqlCommand ("Select * From ArticleTable where [Id]=" + _Id + " AND [NewsDetails]=" + _NewsDetails + " AND [NewsId]=" + _NewsId,conn);
DataSet ds = new DataSet();
SqlDataAdapter adptr = new SqlDataAdapter(_cmd,conn);
adptr.Fill(ds);
//close your database connection
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
}
public partial class Content : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int _Id = Convert.ToInt32(Request.QueryString["Id"]);
int _NewsDetails = Convert.ToInt32(Request.QueryString["NewsDetails"]);
int _NewsId = Convert.ToInt32(Request.QueryString["NewsId"]);
//open your database connection
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\MySite\\Pandheri\\App_Data\\Padheri.mdf;Integrated Security=True;User Instance=True");
conn.Open();
SqlCommand _cmd = new SqlCommand ("Select * From ArticleTable where [Id]=" + _Id + " AND [NewsDetails]=" + _NewsDetails + " AND [NewsId]=" + _NewsId,conn);
DataSet ds = new DataSet();
SqlDataAdapter adptr = new SqlDataAdapter(_cmd);
adptr.Fill(ds);
//close your database connection
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
error:
Invalid object name 'ArticleTable'.
Description: An unhandled exception occurred during the execution of the current web request. Please
review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'ArticleTable'.
OldMonk02
Member
26 Points
61 Posts
Help : Connection property not initialized
Dec 13, 2012 01:40 PM|LINK
hi i am making this news website for college project.and in the homepage i have some url and i am trying to pass query string to my URL.
This is the URL
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <%#Eval("NewsDetails") %> </ItemTemplate> </asp:Repeater> </asp:Content><configuration> <connectionStrings> <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\MySite\Pandheri\App_Data\Padheri.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <compilation debug="true" targetFramework="4.0" /> <authentication mode="Forms"> <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> </authentication> <membership> <providers> <clear /> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> </providers> </membership> <profile> <providers> <clear /> <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" /> </providers> </profile> <roleManager enabled="false"> <providers> <clear /> <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" /> <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> </providers> </roleManager> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> <defaultDocument> <files> <clear /> <add value="default.aspx" /> <add value="Default.htm" /> <add value="Default.asp" /> <add value="index.htm" /> <add value="index.html" /> <add value="iisstart.htm" /> </files> </defaultDocument> </system.webServer> </configuration>using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; using System.Text; public partial class Content : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int _Id = Convert.ToInt32(Request.QueryString["Id"]); int _NewsDetails = Convert.ToInt32(Request.QueryString["NewsDetails"]); int _NewsId = Convert.ToInt32(Request.QueryString["NewsId"]); //open your database connection SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\MySite\\Pandheri\\App_Data\\Padheri.mdf;Integrated Security=True;User Instance=True"); SqlCommand _cmd = new SqlCommand ("Select * From ArticleTable where [Id]=" + _Id + " AND [NewsDetails]=" + _NewsDetails + " AND [NewsId]=" + _NewsId); DataSet ds = new DataSet(); SqlDataAdapter adptr = new SqlDataAdapter(_cmd); adptr.Fill(ds); //close your database connection Repeater1.DataSource = ds; Repeater1.DataBind(); } }Curt_C
All-Star
66014 Points
7639 Posts
Moderator
Re: Help : Connection property not initialized
Dec 13, 2012 01:44 PM|LINK
After SqlConnection conn = new SqlConnection("...")
you need to do
conn.open();
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
OldMonk02
Member
26 Points
61 Posts
Re: Help : Connection property not initialized
Dec 13, 2012 01:48 PM|LINK
Still same error sir.
Fill: SelectCommand.Connection property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized.
Source Error:
Line 26: DataSet ds = new DataSet(); Line 27: SqlDataAdapter adptr = new SqlDataAdapter(_cmd); Line 28: adptr.Fill(ds); Line 29: //close your database connection Line 30:Source File: d:\MySite\Pandheri\Content.aspx.cs Line: 28
RameshRajend...
Star
7983 Points
2099 Posts
Re: Help : Connection property not initialized
Dec 13, 2012 01:51 PM|LINK
Just add this line
SqlCommand _cmd = new SqlCommand ("Select * From ArticleTable where [Id]=" + _Id + " AND [NewsDetails]=" + _NewsDetails + " AND [NewsId]=" + _NewsId, conn)oned_gk
All-Star
30979 Points
6338 Posts
Re: Help : Connection property not initialized
Dec 13, 2012 01:57 PM|LINK
Curt_C
All-Star
66014 Points
7639 Posts
Moderator
Re: Help : Connection property not initialized
Dec 13, 2012 02:02 PM|LINK
you forgot the conn on the CMD
SqlCommand _cmd = new SqlCommand ("Select * From ArticleTable where [Id]=" + _Id + " AND [NewsDetails]=" + _NewsDetails + " AND [NewsId]=" + _NewsId, conn);
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
OldMonk02
Member
26 Points
61 Posts
Re: Help : Connection property not initialized
Dec 13, 2012 02:03 PM|LINK
getting this error
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1502: The best overloaded method match for 'System.Data.SqlClient.SqlDataAdapter.SqlDataAdapter(string, string)' has some invalid arguments
Source Error:
Line 25: SqlCommand _cmd = new SqlCommand ("Select * From ArticleTable where [Id]=" + _Id + " AND [NewsDetails]=" + _NewsDetails + " AND [NewsId]=" + _NewsId,conn); Line 26: DataSet ds = new DataSet(); Line 27: SqlDataAdapter adptr = new SqlDataAdapter(_cmd,conn); Line 28: adptr.Fill(ds); Line 29: //close your database connection<div></div>Curt_C
All-Star
66014 Points
7639 Posts
Moderator
Re: Help : Connection property not initialized
Dec 13, 2012 02:05 PM|LINK
Not on the Adapter line, you want it on the SqlCommand line....
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
OldMonk02
Member
26 Points
61 Posts
Re: Help : Connection property not initialized
Dec 13, 2012 02:06 PM|LINK
i did that sir
still getting the error:
CS1502: The best overloaded method match for 'System.Data.SqlClient.SqlDataAdapter.SqlDataAdapter(string, string)' has some invalid arguments
content.aspx.cs file
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; using System.Text; public partial class Content : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int _Id = Convert.ToInt32(Request.QueryString["Id"]); int _NewsDetails = Convert.ToInt32(Request.QueryString["NewsDetails"]); int _NewsId = Convert.ToInt32(Request.QueryString["NewsId"]); //open your database connection SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\MySite\\Pandheri\\App_Data\\Padheri.mdf;Integrated Security=True;User Instance=True"); conn.Open(); SqlCommand _cmd = new SqlCommand ("Select * From ArticleTable where [Id]=" + _Id + " AND [NewsDetails]=" + _NewsDetails + " AND [NewsId]=" + _NewsId,conn); DataSet ds = new DataSet(); SqlDataAdapter adptr = new SqlDataAdapter(_cmd,conn); adptr.Fill(ds); //close your database connection Repeater1.DataSource = ds; Repeater1.DataBind(); } }OldMonk02
Member
26 Points
61 Posts
Re: Help : Connection property not initialized
Dec 13, 2012 02:09 PM|LINK
content.aspx.cs
public partial class Content : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int _Id = Convert.ToInt32(Request.QueryString["Id"]); int _NewsDetails = Convert.ToInt32(Request.QueryString["NewsDetails"]); int _NewsId = Convert.ToInt32(Request.QueryString["NewsId"]); //open your database connection SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\MySite\\Pandheri\\App_Data\\Padheri.mdf;Integrated Security=True;User Instance=True"); conn.Open(); SqlCommand _cmd = new SqlCommand ("Select * From ArticleTable where [Id]=" + _Id + " AND [NewsDetails]=" + _NewsDetails + " AND [NewsId]=" + _NewsId,conn); DataSet ds = new DataSet(); SqlDataAdapter adptr = new SqlDataAdapter(_cmd); adptr.Fill(ds); //close your database connection Repeater1.DataSource = ds; Repeater1.DataBind(); }error:
Invalid object name 'ArticleTable'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'ArticleTable'.