ASP.NET - Insert Data via Registration  ASP.NET - Insert Data via Registration

Asked By Gautam Raj Kollabathula
14-Feb-11 03:41 AM
hii i am trying to insert data via registration page.

TextBox Uid=utxt;
            TextBox Password=ptxt;
            TextBox ConfirmPassword=ctxt;
            TextBox FirstName=fnametxt;
            TextBox MiddleName=mnametxt;
            TextBox LastName=lnametxt;
            TextBox Sex = sextxt;
            TextBox DOB = dobtxt;
            TextBox POB = pobtxt;
            TextBox FatherName = fathertxt;
            TextBox MotherName = mothertxt;
            TextBox SecurityQuestion = squetxt;
            TextBox SecurityAnswer = sanstxt;
            TextBox Email = emailtxt;
            TextBox PhoneNumber = pnumtxt;
these are the fields i am using. i am using Ms sql as my database and the DB name is exam and the table is GeneralInformation can anyone tell me how do i insert this data????
  div v replied to Gautam Raj Kollabathula
14-Feb-11 03:51 AM
hi,
<asp:Button ID="bntSave" runat="server" Text="Save" OnClick="bntSave_Click" />

cs.page:
protected void bntSave_Click(object sender, EventArgs e)
   {
     SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
     string qry = "INSERT INTO EMP(EmpName,Designation)";
     qry += " Values(@pEmpName,@pDesignation)";
     SqlCommand com = new SqlCommand(qry, conn);
     com.Parameters.AddWithValue("@pEmpName", txtEmpName.Text);
     com.Parameters.AddWithValue("@pDesignation", txtDesignation.Text);
       //Add other textbox like above
     com.Connection.Open();
     com.ExecuteNonQuery();
     com.Connection.Close();
     lblMsg.Text = "Record has been successully added.";
    
   }
  Santhosh N replied to Gautam Raj Kollabathula
14-Feb-11 05:29 AM
You coudl actually pass all these as parameters to SP and inser them or in simple you can pass them as a query but I would recommend using an SP and sending all of them as parameters and insert in the SP to the table..

con = new SqlConnection("conn string");
   
cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = ptxt.Text;
   cmd.Parameters.Add(
"@ConfirmPassword", SqlDbType.VarChar).Value = ctxt.Text;
   cmd.Parameters.Add(
"@EmailID", SqlDbType.VarChar).Value = TextBox4.Text; 
....
   cmd =
new SqlCommand("registerSP", con);
   cmd.CommandType =
CommandType.StoredProcedure;
   con.Open();
   cmd.ExecuteNonQuery();
   con.Close();

and write the SP, registerSP in sql server which accpets the parameetrs you specify here...
  Anoop S replied to Gautam Raj Kollabathula
14-Feb-11 06:06 AM
1st create a stored procedure like this way for insert

CREATE PROCEDURE InsertUser
(
@UserID int,
@Username varchar(50),
@Password varchar(50)
@ConfirmPassword varchar(50)
.......
......
.......
)
AS INSERT INTO Users VALUES(@UserID,@Username, @Password,@ConfirmPassword , ......)


C# code for Insert
Int UserID =int.Parse(textBox1.Text); // // get userid from user string
String Username = Username.Text // get username from user string
String Password = Password.Text  // get password from user
String ConfirmPassword = ConfirmPassword.Text  // get ConfirmPassword from user
....
.....
 
SqlConnection conn = new SqlConnection"
DataSource=localhost;Database=db_First;Integrated Security=SSPI");
SqlCommand command = new SqlCommand("InsertUser", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@UserID", SqlDbType.Int).Value = UserID ;
command.Parameters.Add("@Username", SqlDbType.VarChar).Value = Username;
command.Parameters.Add("@Password", SqlDbType.VarChar).Value = Password;
.......
.......
conn.Open(); int rows = command.ExecuteNonQuery();
conn.Close();

Create New Account
help
How to insert null values in sql database table Here I have created a table with 42 columns. . . . but in that i want to insert data in the then only data gets saved in database as if all the dinamically added controls are created and data is provided. . . . but if users select less text box then error occurs that columCount; i++) { / / Code to generate dynamic controls and insert into the table } } } if you are creating the sql statement dynamically then you can do something like this when preparing sql staements CREATE TABLE test( col1 varchar (10) , col2 varchar (10) , col3 varchar (10) ) DECLARE @sSQL VARCHAR ( MAX your dynamic staement, then by default it would take null value then do like this CREATE TABLE test( col1 varchar (10) , col2 varchar (10) , col3 varchar (10) ) DECLARE @sSQL VARCHAR ( MAX pass it. Make sure you assign the right default value to the varialble. Easy ah? CREATE PROCEDURE [dbo].[SP_GetData] ( @UserId INT, @TopCount INT = 5, @ErrorCode INT OUTPUT, @ErrorMessage NVARCHAR(300) OUTPUT ) AS it goes. . . private void SaleSave_Click(object sender, EventArgs e) { if (SaleTotalTran.SelectedIndex = = 0) { con = new SqlConnection("Data Source = RISHI-PC \ RISHI; Initial Catalog = retail; User ID = sa; Password = helloworld"); con.Open
Store Procedure can anyone tell me how to implement store procedure in Asp .net with c# First open Microsoft SQL Server -> Enterprise Manager, then navigate to the database in which you want to create the stored procedure and select New Stored Procedure. See the below Stored Procedure Properties for what to enter, then click OK. Now
inserting all form values in a table using stored procedure hi everyone. . . . . . i have problem like . . .i have created a web page which is having id, fromdate, todate , request and type which is a dropdownlist and the rest are textboxes and i have created stored procedures to insert these all values into the table but now from my web page how can i cal that stored procedure to insert all my values into table i tried like this but in between i
on clicking a button by using datasets and data adapter? Hi, follow these steps - 1.create object of sqlcommand 2.assign connection, commandtype, commadtext to it 3.add parameters to their names, dbtype 4.create object of dataadpter, assign command object to its insertcommand property 5.execute(ie fill ) it with the dataset public static SqlDataAdapter CreateCustomerAdapter( SqlConnection connection) { SqlDataAdapter adapter = new SqlDataAdapter(); / / Create the SelectCommand. SqlCommand command = new SqlCommand("SELECT * FROM Customers " + "WHERE Country = @Country AND City = @City", connection); / / Add the parameters for the SelectCommand. command.Parameters.Add("@Country", SqlDbType.NVarChar, 15); command.Parameters.Add("@City SqlDbType.NVarChar, 15); adapter.SelectCommand = command; / / Create the InsertCommand. command = new SqlCommand( "INSERT INTO Customers (CustomerID, CompanyName) " + "VALUES (@CustomerID, @CompanyName)", connection); / / Add the parameters for the InsertCommand. command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID"); command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName"); adapter.InsertCommand = command; / / Create
how do you go about it? (A) What is Manifest? (B) Where is version information stored of an assembly? (I) Is versioning applicable to private assemblies? (B) What is GAC? (I IUKNOWN interface in short? (I) Can you explain what DCOM is? (B) How do we create DCOM object in VB6? (A) How to implement DTC in .NET? (A) How many types Thread.Join () in threading? (A) What are Daemon threads and how can a thread be created as Daemon? (A) How is shared data managed in threading? (I) Can we use events the remote object has to inherit? (I) what are two different types of remote object creation mode in .NET ? (A) Describe in detail Basic of SAO architecture of Remoting? (A) What published or precreated objects in Remoting? (A) What are the ways in which client can create object on server in CAO model? (A) Are CAO stateful in nature? (A) To create objects in CAO with ‘new’ keyword what should be done? (I) Is it a good order that the method can be used as WebService? (A) What are the steps to create a web service and consume it? (A) Do webservice have state? Chapter 5: Caching Concepts you compare ASP.NET sessions with classic ASP? (B) Which are the various modes of storing ASP.NET session? (A) Is Session_End event supported in all session modes? (A) What are