I have 3 rows and 4 columns with textboxes in it i have to store all the textboxes data at a single click using asp.net and C sharp
storing multiple rows data in save button using asp.net and c sharp
Hello,
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jul 27, 2012, 1:49 PM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Login_and_signup
{
public partial class Registration : System.Web.UI.Page
{
protected void btnSubmit_Click(object sender, EventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection sqlConnection = new SqlConnection(connStr);
sqlConnection.Open();
string sqlQuery = "INSERT INTO Users(FirstName,LastName,UserName,Password,Address) VALUES(@FirstName,@LastName,@UserName,@Password,@Address)";
SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection);
sqlCommand.CommandType = CommandType.Text;
sqlCommand.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFirstName.Text.Trim();
sqlCommand.Parameters.Add("@LastName", SqlDbType.VarChar).Value = txtLastName.Text.Trim();
sqlCommand.Parameters.Add("@UserName", SqlDbType.VarChar).Value = txtUserName.Text.Trim();
sqlCommand.Parameters.Add("@Password", SqlDbType.VarChar).Value = txtPassword.Text.Trim();
sqlCommand.Parameters.Add("@Address", SqlDbType.VarChar).Value = txtAddress.Text.Trim();
int irows = sqlCommand.ExecuteNonQuery();
lblMessage.Text = "User inserted successfully...";
}
}
}
Thanks