Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a Enquiry form in my asp.net C# website..Using sql server
i want to stored the values enterd in my form to database....
can anyone help me about this...
please help me out
Posted

first you create table in database..
then use sql query to insert values in to the table..
 
Share this answer
 
Comments
manishmns12 27-Feb-14 6:09am    
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=HP-PC\SQLEXPRESS;Initial Catalog=Enquiry;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("sp_userinformation", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@Emailid", Emailid);
cmd.Parameters.AddWithValue("@Phoneno", Phoneno);
cmd.Parameters.AddWithValue("@Address", Address);
cmd.Parameters.AddWithValue("@Pincode", Pincode);
cmd.Parameters.AddWithValue("@Heard", Heard);
cmd.Parameters.AddWithValue("@Enquiryabout", EnquiryAbout);
cmd.Parameters.AddWithValue("@Message", Message);
cmd.ExecuteNonQuery();
con.close();
}
}





Error:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'CommandType' does not exist in the current context

Source Error:


Line 19: con.Open();
Line 20: SqlCommand cmd = new SqlCommand("sp_userinformation", con);
Line 21: cmd.CommandType = CommandType.StoredProcedure;
Line 22: cmd.Parameters.AddWithValue("@Name", Name);
Line 23: cmd.Parameters.AddWithValue("@Emailid", Emailid);




plz plz help me out
Hi,
First you have to create sql tables and needful sps.

here iam attaching a simple example.

SQL
Create procedure insert
(@ColumnValue1,@ColumnValue2,@ColumnValue3)
{
insert into tablename (Column1,Column2,Column3)
values(@ColumnValue1,@ColumnValue2,@ColumnValue3)
}



.net part-- create a method for inserting values to db and call this method from the submit button click or you cam writethe full code inside the button click.
C#
SqlConnection con=new sqlconnection("give ur connection string here");
sqlcommand cmd=new sqlcommand();
con.open();
cmd=new sqlcommand("insert",con);
cmd.commandtype=commandtype.storedprocedure;
cmd.parameters.addwithvalue("@ColumnValue1",txtbox1.text);
cmd.parameters.addwithvalue("@ColumnValue2",txtbox2.text);
cmd.parameters.addwithvalue("@ColumnValue3",txtbox3.text);
cmd.ExecuteNonQuery();
con.close();


Hope this will help you to get a basic idea.
 
Share this answer
 
Comments
manishmns12 27-Feb-14 6:07am    
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=HP-PC\SQLEXPRESS;Initial Catalog=Enquiry;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("sp_userinformation", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@Emailid", Emailid);
cmd.Parameters.AddWithValue("@Phoneno", Phoneno);
cmd.Parameters.AddWithValue("@Address", Address);
cmd.Parameters.AddWithValue("@Pincode", Pincode);
cmd.Parameters.AddWithValue("@Heard", Heard);
cmd.Parameters.AddWithValue("@Enquiryabout", EnquiryAbout);
cmd.Parameters.AddWithValue("@Message", Message);
cmd.ExecuteNonQuery();
con.close();
}
}





Error:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'CommandType' does not exist in the current context

Source Error:


Line 19: con.Open();
Line 20: SqlCommand cmd = new SqlCommand("sp_userinformation", con);
Line 21: cmd.CommandType = CommandType.StoredProcedure;
Line 22: cmd.Parameters.AddWithValue("@Name", Name);
Line 23: cmd.Parameters.AddWithValue("@Emailid", Emailid);




some plz plz help me out
manishmns12 27-Feb-14 6:12am    
i used using.system.data;

and i wrkd smhow..but still error message is:

Compiler Error Message: CS1061: 'System.Data.SqlClient.SqlConnection' does not contain a definition for 'close' and no extension method 'close' accepting a first argument of type 'System.Data.SqlClient.SqlConnection' could be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 30: cmd.Parameters.AddWithValue("@Message", Message);
Line 31: cmd.ExecuteNonQuery();
Line 32: con.close();
Line 33: }
Line 34: }

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