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 !




vb.net connection string with insert coding


Posted Date: 05 Sep 2008      Total Responses: 3

Posted By: vidhya       Member Level: Gold     Points: 1


vb.net coding with connection string



Responses

Author: Geetha    05 Sep 2008Member Level: GoldRating:     Points: 2
Dim objConn As New SqlConnection("data source=NEWSERVER;user id=sa;pwd=SS123#;initial catalog=SchoolProject;")

Public Sub ExecuteNonQueryMethod(ByVal sSql As String)
'Function used to execute the sql stmt such as inset, update & delete
objConn.Open() 'Opening the database connection
Dim objCmd As New SqlCommand(sSql, objConn) 'Creating a command object to execute the sql stmt with the sql stmt and the connection object as its parameter
objCmd.ExecuteNonQuery() 'Calling ExecuteNonQuery method associated with the command object to execute the sql stmt
objConn.Close() 'Closing the database connection
End Sub



Author: ANIL PANDEY    05 Sep 2008Member Level: DiamondRating:     Points: 2
hi,

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim con As New SqlConnection(conString)
Dim cmd As SqlCommand
Dim query As String

If btnAdd.Text = "Add" Then
Try
con.Open()
query = "insert into Jobs(UID,Proj_ID,Job,AssignedBy,Date_Time,Hours_Worked) values(" & Session("UID") & "," & ddlProject.SelectedValue & ",'" & txtJob.Text & "','" & txtAssignedby.Text & " ','" & txtDate.Text & "'," & CInt(txtHours.Text) & ")"
cmd = New SqlCommand(query, con)
cmd.ExecuteNonQuery()
con.Close()
fillJobs()
clearForm()
Catch ex As Exception
Response.Write(ex.Message)
End Try
ElseIf btnAdd.Text = "Update" Then
Try
con.Open()
query = "update Jobs set Proj_ID=" & ddlProject.SelectedValue & ",Job='" & txtJob.Text & "',AssignedBy='" & txtAssignedby.Text & "',Date_Time='" & txtDate.Text & "',Hours_Worked=" & CInt(txtHours.Text) & " where JobID=" & jobId
cmd = New SqlCommand(query, con)
cmd.ExecuteNonQuery()
con.Close()
fillJobs()
clearForm()
btnAdd.Text = "Add"
btncancel.Visible = False

Catch ex As Exception
Response.Write(ex.Message)
End Try
End If
End Sub

Thanks and Regards
Anil kumar Pandey


Author: vidhya    05 Sep 2008Member Level: GoldRating:     Points: 2
i have written my insert operation but in messagebox.show is not working



this is my code

Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
myConnection = New SqlConnection("server=localhost;uid=sa;pwd=;database=Vidhya")
'you need to provide password for sql server
myConnection.Open()
myCommand = New SqlCommand("Insert into Jobs values 12,'IT Manager',100,300,_myConnection")
ra = myCommand.ExecuteNonQuery()

MessageBox.Show("New Row Inserted" & ra)


myConnection.Close()



End Sub


Post Reply
You must Sign In to post a response.
Next : Doubt
Previous : ReadXmlSchema File in .Net
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

budget conference call

Contact Us    Privacy Policy    Terms Of Use