can any one help me
im new to dot net my program is
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Data.Sql Client;
public partial class _Default : System.Web.UI.P age
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
protected void Page_Load(objec t sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@ "Data Source=.\SQLEXP RESS;AttachDbFi lename=|DataDir ectory|\project .mdf;Integrated Security=True;U ser Instance=True") ;
con.Open();
SqlCommand cmd = new SqlCommand ("select * from CountryMaster", con);
da = new SqlDataAdapter( cmd);
ds = new DataSet();
da.Fill(ds,"Cou ntryMaster");
GridView1.DataS ource = ds.Tables["CountryMas ter"];
GridView1.DataB ind();
}
protected void Button1_Click(o bject sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("ins ert into CountryMaster values('"+TextB ox1.Text+"')",c on);
cmd.ExecuteNonQ uery();
}
}
and i am having the error can u solve it
Server Error in '/project' Application.
--------------------------------------------------------------------------------
ExecuteNonQuery : 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.InvalidO perationExcepti on: ExecuteNonQuery : Connection property has not been initialized.
Source Error:
Line 40: {
Line 41: SqlCommand cmd = new SqlCommand("ins ert into CountryMaster values('"+TextB ox1.Text+"')",c on);
Line 42: cmd.ExecuteNonQ uery();
Line 43:
Line 44: }
Source File: c:\Documents and Settings\Admini strator\My Documents\Visua l Studio 2005\WebSites\p roject\Default. aspx.cs Line: 42
Stack Trace:
[InvalidOperatio nException: ExecuteNonQuery : Connection property has not been initialized.]
System.Data.Sql Client.SqlComma nd.ValidateComm and(String method, Boolean async) +80
System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe) +133
System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() +149
_Default.Button 1_Click(Object sender, EventArgs e) in c:\Documents and Settings\Admini strator\My Documents\Visua l Studio 2005\WebSites\p roject\Default. aspx.cs:42
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +96
System.Web.UI.W ebControls.Butt on.RaisePostBac kEvent(String eventArgument) +116
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +31
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +32
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +72
System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +3839
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.507 27.832; ASP.NET Version:2.0.507 27.832
im new to dot net my program is
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Data.Sql Client;
public partial class _Default : System.Web.UI.P age
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
protected void Page_Load(objec t sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@ "Data Source=.\SQLEXP RESS;AttachDbFi lename=|DataDir ectory|\project .mdf;Integrated Security=True;U ser Instance=True") ;
con.Open();
SqlCommand cmd = new SqlCommand ("select * from CountryMaster", con);
da = new SqlDataAdapter( cmd);
ds = new DataSet();
da.Fill(ds,"Cou ntryMaster");
GridView1.DataS ource = ds.Tables["CountryMas ter"];
GridView1.DataB ind();
}
protected void Button1_Click(o bject sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("ins ert into CountryMaster values('"+TextB ox1.Text+"')",c on);
cmd.ExecuteNonQ uery();
}
}
and i am having the error can u solve it
Server Error in '/project' Application.
--------------------------------------------------------------------------------
ExecuteNonQuery : 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.InvalidO perationExcepti on: ExecuteNonQuery : Connection property has not been initialized.
Source Error:
Line 40: {
Line 41: SqlCommand cmd = new SqlCommand("ins ert into CountryMaster values('"+TextB ox1.Text+"')",c on);
Line 42: cmd.ExecuteNonQ uery();
Line 43:
Line 44: }
Source File: c:\Documents and Settings\Admini strator\My Documents\Visua l Studio 2005\WebSites\p roject\Default. aspx.cs Line: 42
Stack Trace:
[InvalidOperatio nException: ExecuteNonQuery : Connection property has not been initialized.]
System.Data.Sql Client.SqlComma nd.ValidateComm and(String method, Boolean async) +80
System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe) +133
System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() +149
_Default.Button 1_Click(Object sender, EventArgs e) in c:\Documents and Settings\Admini strator\My Documents\Visua l Studio 2005\WebSites\p roject\Default. aspx.cs:42
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +96
System.Web.UI.W ebControls.Butt on.RaisePostBac kEvent(String eventArgument) +116
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +31
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +32
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +72
System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +3839
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.507 27.832; ASP.NET Version:2.0.507 27.832
Comment