Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#
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:
SQL
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
v6

Not unless the table resides in master database. Which database does your table reside in? What is the error you are getting?
 
Share this answer
 
v2
Comments
Rambo_Raja 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.
dan!sh 4-Jun-13 6:40am    
Seems there is something wrong with the configuration file. Can you update question with it?
Rambo_Raja 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!
dan!sh 4-Jun-13 9:17am    
Please update the question with config file.
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..
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900