CSharp Insert Data To Sql Server Through Sqlconnection – ADO.Net Database

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<script runat=server>
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
    Dim DBConn as SQLConnection
    Dim DBAdd As New SQLCommand
'        DBConn = New SQLConnection("server=localhost;" _
 '           & "Initial Catalog=TT;" _
  '          & "User Id=sa;" _
   '         & "Password=yourpassword;")
    DBConn = New SQLConnection("Data Source=whsql-v08.prod.mesa1.secureserver.net;Initial Catalog=DB_49907;User ID=w3mentoruser;Password='password';")
    DBAdd.CommandText = "Insert Into Employee (" _
        & "LastName, FirstName, Salary " _
        & ") values ('" & txtLastName.Text & "'," _
        & "'" & txtFirstName.Text _
        & "'," & txtSalary.Text & ")"
 
    DBAdd.Connection = DBConn
    DBAdd.Connection.Open
    DBAdd.ExecuteNonQuery()
End Sub
</script>
<html>
<head>
<title>Adding SQL Server Data</title>
</head>
<body LEFTMARGIN="40">
<form runat="server">
<br />
Last Name:
<br />
<asp:textbox id="txtLastName" runat="Server"/>
<br />
First Name:
<br />
<asp:textbox id="txtFirstName" runat="Server"/>
<br />
Salary:
<br />
<asp:textbox id="txtSalary" runat="Server"/>
<br /><br />
<asp:button id="butOK" text="OK" onclick="SubmitBtn_Click" runat="server"/>
</form>
</body>
</html>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.