Reputation: 53
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=LENOVO;Initial Catalog=dbMACARON;Integrated Security=True"); SqlCommand com = new SqlCommand("Select * from PRODUCT");
public void Bind()
{
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
con.Open();
com.Connection = con;
com.ExecuteNonQuery();
da.Fill(ds, "PRODUCT");
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
com.Connection = con;
SqlDataReader dr;
dr = com.ExecuteReader();
string id = "0";
Source Error:
Line 31: protected void Page_Load(object sender, EventArgs e)
Line 32: {
Line 33: con.Open();
Line 34: com.Connection = con;
Line 35: SqlDataReader dr;
It said error on my con.Open could not open database, what did i go wrong? sorry im fresh so i need guidance ,
there some source error it tells me
Upvotes: 1
Views: 123
Reputation: 53
I HAVE FIX IT MY SELF!! BUT THANKS FOR EVERYONE FOR TRYING HELPING ME OUT !! THANKS YOU!!
what i do is i put double "\" between lenovo and ebg example in sqp connection..
EXAMPLE:
public partial class SignUp : System.Web.UI.Page { SqlConnection con = new SqlConnection("Data Source=LENOVO\EBG; Initial Catalog=dbMACARON; integrated security= True"); SqlCommand com = new SqlCommand("Select * from CUSTOMER"); public void Bind() { SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); con.Open(); com.Connection = con; com.ExecuteNonQuery(); da.Fill(ds, "CUSTOMER"); GridView1.DataSource = ds; GridView1.DataBind(); con.Close(); }
weird in this web it didt show double "\" in here... but nway thanks.
Upvotes: 0
Reputation: 1
Try this as it is. 1. Go to Tools menu-> folder option-> view tab and unCheck the following checkbox with name that HIDE EXTENSION FOR KNWON FILE TYPES.
2.Now crate the file as sql with extension udl i.e sql.udl. It will ask you for confirmation press Yes.
Right click on that file and select open with OLEDB CORE DATASERVICE. It will open the dialog box as follows. ![enter image description here][2]
Go to provider tab and select Microsoft OLEDB PROVIDER FOR SQL SERVER.. AND THEN CLICK ON NEXT BUTTON.
finally close that window and now open that udl file with notepad. Copy the content starting from the provider name to the end and paste it into your coding page.
Thats it. It will not show you error again.
Upvotes: 0
Reputation: 797
if you are using sql express edition try this:
SqlConnection con = new SqlConnection("Data Source=.\SQLExpress;Initial Catalog=dbMACARON;Integrated Security=True");
Upvotes: 1
Reputation: 164
Upvotes: 0