0

Hi All,
For more than two days I m trying this problem. Some one
please help me out. My scenario is I want to directly insert data into
my table from the input which I get it from text boxes. Here is my
code...

con = new SqlConnection();
       con.ConnectionString = "Data Source=santhosh;Initial
Catalog=ecop;User ID=sa;Password=test";
       con.Open();
       SqlCommand cmd = new SqlCommand();
       cmd.CommandText="INSERT INTO
com(st_id,name,addres,phone,ct_type,brief_incident,suspect,date,time)
VALUES(@st_id,@name,@addres,@phone,@ct_type,@brief_incident,@suspect,@date,@time)";
       cmd.Parameters.Add(new
SqlParameter("@st_id",DropDownList1.SelectedValue));
       cmd.Parameters.Add(new SqlParameter("@name",TextBox1.Text));
       cmd.Parameters.Add(new SqlParameter("@addres",TextBox2.Text));
       cmd.Parameters.Add(new SqlParameter("@phone",TextBox3.Text));
       cmd.Parameters.Add(new
SqlParameter("@ct_type",DropDownList2.SelectedItem));
       cmd.Parameters.Add(new
SqlParameter("@brief_incident",TextBox6.Text));
       cmd.Parameters.Add(new
SqlParameter("@suspect",TextBox4.Text));
       cmd.Parameters.Add(new SqlParameter("@date",TextBox5.Text));
       cmd.Parameters.Add(new SqlParameter("@time",TextBox7.Text));
      [B] SqlDataReader  dr = cmd.ExecuteReader();[/B]------> In this
particular line I m getting Connection property has not been
initialized.

some one help me out to get ride of this problem...

With Regards,
Santhosh V Kumar

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by asal80
0

The connection string specifies information about how to initialize a connection to a data store.

It contains keyword/value pairs. the first pair is always the Provider or Driver. The following pairs will correspond with the data required to initialize the provide / driver.

Some Example Keywords:

SQL ODBC: Server, Database, Uid (user), Pwd (password), Trusted_Connection, MARS_Connection (multiple active record sets), Encrypt, AttachDbFilename,

SQLOLEDB: Data Source, Initial Catalog (database to connect to), UserId, Password, Integrated Security, Failover Partner (for mirroring).

Some example connection strings:

SqlConnection (.NET) standard Security:

"Data Source=ServerAddress;Initial Catalog=DataBase;User Id=username;Password=password;"

ODBC - PostgreSQL driver:

"Driver={PostgreSQL};Server=IP address;Port=5432;Database=DataBase;Uid=username;Pwd=password;"
=================
<<Snipped Site name>>

Edited by __avd: Snipped site name.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.