You are a new dotnet programmer.This is the simple coding for to connect and store a data in database.
private void submit_Click(object sender, System.EventArgs e) { SqlConnection con=new SqlConnection("Server=system14;database=arunlat;uid=sa;pwd="); string SqlCmd="insert into arun values('"+text1.Text+"','"+text2.Text+"','"+text3.Text+"','"+text4.Text+"','"+text5.Text+"','"+rdrgender.SelectedItem.Text+"','"+dropdown.SelectedItem+"')"; SqlCommand cmd=new SqlCommand(SqlCmd,con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); }
|
| Author: Bunty 02 Sep 2008 | Member Level: Diamond Points : 1 |
Hi, Nice code for a novice.Helpfull too.Keep posting such useful information. Thanks and Regards S.S.Bajoria
|
| Author: nirmala 03 Sep 2008 | Member Level: Bronze Points : 2 |
imports system.data.sql
Private Sub User_Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim connString As String = "server=\SQLEXPRESS;uid=sa;password=ursqlserverpasswor;database=urdatabasename;" End Sub
Private Sub CmdLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdLogin.Click
Dim connString As String = "server=\SQLEXPRESS;uid=sa;password=ursqlserverpassword;database=quiz;" Dim conn As New SqlConnection(connString) 'Dim bexitapplication As Boolean 'Dim strSQL As String Dim DA As New SqlDataAdapter Dim DS As New DataSet 'Dim dr As DataRow 'Dim valid As Boolean Dim query As String = "Select username,password From login WHERE username='" & txtusername.Text.ToString & "' and password='" & txtpwd.Text & "'"
conn.Open() 'Dim cmd As New SqlCommand("Select username,password From login WHERE username='" + txtusername.Text.ToString + "' and password='" + txtpwd.Text + "'", conn) 'DA.SelectCommand = New SqlCommand("Select username,password From login WHERE username='" & txtusername.Text.ToString & "' and password='" & txtpwd.Text & "'", conn) Dim cmd As SqlCommand = New SqlCommand(query, conn) Dim dr As SqlDataReader = cmd.ExecuteReader If dr.HasRows = True Then Label3.Text = "Loggingg......." MsgBox("login please hold on......") Dim frm As New WelcomeScreen WelcomeScreen.Show() Else 'Label3.Text = "Invalid Username and Password" 'Label3.Text = " " ' MsgBox("Invalid Username and password") Label3.Text = "Invalid Username and Password!"
MsgBox("Please try again") Label3.Text = " " txtusername.Text = " " txtpwd.Text = " " txtusername.Focus()
End If
DS.Clear() 'DA.Fill(DS, "login")
End Sub instead of selct command u use insert into login(username,password) values('name','121323');
|