Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



I am unable to enter the data into database.

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 15-11-2009
Member
 
Join Date: Nov 2009
Posts: 1
I am unable to enter the data into database.
  

Hello Friends,

I am a beginner in ADO.net. I have a simple form with three text field and a submit button. Now i am trying to enter the text field values into database. I have database name: "ashish" with a table name "ashish1". Now what i did, i created a connection through wizard. And that connection generate a connection string "Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\ashish.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True". And on botton event i am entering this code:

private void button1_Click(object sender, EventArgs e)
{
try
{
/*SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=SQLEXPRESS;Initial Catalog=ashish;Integrated Security=True;Connect Timeout=30;User Instance=True";
con.Open();*/
string quary = "insert into ashish1(name, address, phone) values(@name, @address, @phone)";
SqlCommand cmd= new SqlCommand();
cmd.CommandText = quary;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@name", textBox1.Text.ToString());
cmd.Parameters.AddWithValue("@address", textBox2.Text.ToString());
cmd.Parameters.AddWithValue("@phone", textBox3.Text.ToString());
cmd.ExecuteNonQuery();
}
catch (Exception ed)
{
MessageBox.Show(ed.ToString());
}
}

Now when i click upon submit button, system is showing me an error. Error message is:

System.InvalidOperationExection: ExecuteNonQuery: Connection property has not been initialized.
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at WindowsApplication1.form2.button1_click(...) in ..\form2.cs

Please guys guide me how do i insert the data.

Thanks,

Ashish

Reply With Quote
  #2  
Old 07-06-2011
Member
 
Join Date: Apr 2009
Posts: 567
Re: I am unable to enter the data into database.

For that I will do the following. In a table of the DB files are saved the personal taste of candidates. With the form xxx1 you can capture the person or change data. As can be seen, the fields are not numeric or delimited by apostrophes Boolean. Of course, it is essential to fill in all fields of the record. Of course, it may be that certain fields are required. These fields are required can be defined when we built our table using the database.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "I am unable to enter the data into database."
Thread Thread Starter Forum Replies Last Post
Representing a data in a database kALAMATHI Software Development 3 21-01-2011 07:47 AM
Storing database data into Map Miles Runner Software Development 5 20-02-2010 01:17 AM
enter key stuck! Unable to <enter> and 'choose' bootmenu royjacob Hardware Peripherals 3 09-11-2009 10:50 PM
My data does not fit in my database Happy46 Software Development 3 21-10-2009 06:08 PM
How to enter Data in Shared Excel Workbook Kamran Windows Software 3 30-04-2009 11:44 AM


All times are GMT +5.5. The time now is 12:45 AM.