C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Connect a new Database


Posted Date: 18 Apr 2008    Resource Type: Code Snippets    Category: ADO.NET

Posted By: Arunkumar       Member Level: Silver
Rating:     Points: 7



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();
}







Responses

Author: Bunty    02 Sep 2008Member 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 2008Member 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');



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Query a SQL Server Database in C# with ADO.NET
Previous Resource: VB.NET Class for Database manipulation
Return to Discussion Resource Index
Post New Resource
Category: ADO.NET


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

teleconferencing

Contact Us    Privacy Policy    Terms Of Use