Click here to Skip to main content
13,193,650 members (59,438 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
when i click insert button that i have created on asp.net application all records that i enter automatically gets stored in my employee_tab(table).my code for insert button is as follows:
SqlConnection con = new SqlConnection();
SqlCommand com = new SqlCommand();
com.Connection = con;
con.ConnectionString = (@"add name="constr"; connectionString ="Data Source=localhost;Initial Catalog=master;Integrated Security=True");
    int a = Convert.ToInt32(txtEmpId.Text);
    string  b = (txtEmp_name.Text );
int c = Convert.ToInt32(txtSalary.Text);
string  d = (txtCity.Text);
com.CommandText = "INSERT INTO employee_tab(EmpId,Emp_name,Salary,City) values (@a,@b,@c,@d)";
com.Parameters.AddWithValue("@a" , a );
com.Parameters.AddWithValue("@b",b );
com.Parameters.AddWithValue("@c", c );
com.Parameters.AddWithValue("@d",d );
com.Connection.Open();
com.ExecuteNonQuery();
com.Connection.Close();

Also i have created a SP and it is also giving error.i want to do this all with help of SP only.
stored proc is as follows:
create procedure spdatabaseconnectivity
( 
    @EmpId int,
    @Emp_name,
    @Salary,
    @City)
as
begin
    (insert into employee_tab(EmpId,Emp_name,Salary,City)
    values (@EmpId,@Emp_name,@Salary,@city))
end

is my connection string is correct?
help me solve this que.my table resides in system database.i think there is a problem with my connection string.the error i am getting when executing c# code is : Only one element allowed per config file and if present must be the first child of the root element.
Thanks.
Posted 3-Jun-13 23:44pm
v6
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Not unless the table resides in master database. Which database does your table reside in? What is the error you are getting?
  Permalink  
v2
Comments
R_sharma 4-Jun-13 5:59am
   
my table resides in system database.i think there is a problem with my connection string.the error i am getting when executing c# code is : Only one <configsections> element allowed per config file and if present must be the first child of the root <configuration> element.
d@nish 4-Jun-13 6:40am
   
Seems there is something wrong with the configuration file. Can you update question with it?
R_sharma 4-Jun-13 6:53am
   
ya sure..i have done some changes in conFig file connection string is as follows:
<add name="constr" connectionstring="Data Source=.;Initial Catalog=master;Integrated Security=True" providername="System.Data.SqlClient">
but danish now a new error is comming i.e,could not find stored procedure.i dont know where i m wrong?Help!
d@nish 4-Jun-13 9:17am
   
Please update the question with config file.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,

For creating connection string plz look into the following link :

http://www.connectionstrings.com/[^]


and after modifying your connections string , insert data using stored procedure :

Example : insert-record-in-database-using-stored.html


Please have a look into the solution..
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171018.2 | Last Updated 4 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100