How to store textbox value in database

Solved/Closed
NewUser - Mar 30, 2010 at 02:55 AM
 sham - Jan 26, 2015 at 08:34 PM


hello.. im a new user of asp.net.. im creating an asp.net webpage using VB code.

I wanted to know how to store the textbox value(input from user) into the sql databse table..
i need a sample codef or this.
im using ASP.NET 3.5, Visual Studio 2008, SQL server 2005.

Help is really appreciated.. thank you
Related:

7 replies

sqlconnection myconn=new sqlconnection();
myconn.connectionstring="-------specify path here------";
myconn.open();
string qry="insert into table1 values('"+username+"','"+password+"')";
sqlcommand cmd=new sqlcommand(qry,myconn);
cmd.ExecuteNonQuery();
myconn.Close();
49
exactly correct,thanks
0
correct 1
0
correct
0
in this code missing where passing this value colm was missing
0
Hello mam.........
In where I can fetch the path
0
sqlconnection myconn=new sqlconnection();
myconn.connectionstring="-------specify path here------";
myconn.open();
string qry="insert into table1 values('"+username+"','"+password+"')";
sqlcommand cmd=new sqlcommand(qry,myconn);
cmd.ExecuteNonQuery();
myconn.Close();
26
your query is perfect
0
thank you......
0
thanx nidhi ........
0
pradeep kumar
Jul 29, 2013 at 07:18 AM
thanks .ur code is perfect.
0
please writ the code for vb to ms access database
0
yes. I found the answer to this qn.
on my html page I have the textboxes where the user will input their data.
then they have to click on submite after filling the form.

i will attach sample code for you.

html code :

<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Place"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
</div>
</form>
</body>

asp.net code :

Imports System.Data
Imports System.Data.SqlClient

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'assigning string with values of textbox.
Dim strName, strPlace As String
strName = TextBox1.Text
strPlace = TextBox2.Text
'declaring sql connection. please complete it by urself
Dim sqlcon As New SqlConnection("server=;database=;uid=;password=")

'checking if connection is open. if open close it and open again.
If sqlcon.State = ConnectionState.Open Then
sqlcon.Close()
End If
sqlcon.Open()
Dim strcommand As String
'the insert command is stored in strcommand
'Table Name : Contact
'Column of table : Name, Place
strcommand = "Insert into Contact(Name,Place) values ('" + strName + "','" + strPlace + "')"
Dim sqlcomm As New SqlCommand(strcommand, sqlcon)
Dim o As String = sqlcomm.ExecuteNonQuery()
label3.text = "Entry Added!"

End Sub
End Class
15
thanks that code is 2 much help me. thank u so much.
0
'checking if connection is open. if open close it and open again'..how? please teach me
0
it will execute nicely.....
13

Didn't find the answer you are looking for?

Ask a question
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;


public partial class _Default : System.Web.UI.Page
{



protected void Page_Load(object sender, EventArgs e)
{

}


protected void Button1_Click1(object sender, EventArgs e)
{


SqlCommand cmd;
SqlConnection con = new SqlConnection(@"Data Source=sts-pc\sqlexpress;Initial Catalog=master;Integrated Security=True;");
con.Open();
cmd = new SqlCommand("INSERT INTO login VALUES('" + TextBox1.Text + "', '" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "')", con);
cmd.ExecuteNonQuery();

con.Close();
Response.Redirect("http://localhost:4162/WebSite8/Default3.aspx");
}
5
thank you. my qn was answered. I was using vb and not c#.
1
select record in database in c#.net codes
0