i have tried lots of times but i got the error.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string constring = ConfigurationManager.ConnectionStrings["conn"].ConnectionString();
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SPuserid";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@name",txtname.Text);
cmd.Parameters.AddWithValue("@password",txtpwd.Text);
cmd.Parameters.AddWithValue("@address", txtaddr.Text);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Response.Write("name:"+dr[0]);
}
gv.DataSource = dr;
gv.DataBind();
conn.Close();
}
}
And web.config file
but i got this error "The ConnectionString property has not been initialized."
can any one fix this
thanks
Dnyandeo ShindePosted Jun 15, 2013, 5:54 AM
You have to write connection string like this way to avoid error.
string constring = ConfigurationManager.ConnectionStrings["conn"].ToString();
SqlConnection con = new SqlConnection(constring );
aditya immadiPosted Jun 13, 2013, 9:22 AM
there is another error in the same programme
SqlDataReader dr = cmd.ExecuteReader();
the above line shows the fallowing error.....
"No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type."
can any one explain and correct this error
thanks & Regards
Pankaj PandeyPosted Jun 13, 2013, 9:01 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string constring = ConfigurationManager.ConnectionStrings["conn"].ConnectionString();
SqlConnection conn = new SqlConnection(constring );
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SPuserid";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@name",txtname.Text);
cmd.Parameters.AddWithValue("@password",txtpwd.Text);
cmd.Parameters.AddWithValue("@address", txtaddr.Text);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Response.Write("name:"+dr[0]);
}
gv.DataSource = dr;
gv.DataBind();
conn.Close();
}
}
Puneet AMaRPosted Jun 13, 2013, 8:51 AM
i think the error is in connection string which is in web.config file.u should do one thing that if u have created database seperately in DBMS then from dere u can see the properties of database ..and then from dere u can see the connection sting property.from dere u can get the connection string like dis one....."connectionString="Data Source=.;Initial Catalog=june;Persist Security Info=True;User ID=sa;Password=123"" ....and copy it in your web.config file .just try it on.
Santhosh Kumar JayaramanPosted Jun 13, 2013, 8:00 AM
Try this.
Instead of
SqlConnection conn = new SqlConnection();
use
SqlConnection conn = new SqlConnection(constring );