| Author: Geetha 05 Sep 2008 | Member Level: Gold | Rating: 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 2008 | Member Level: Diamond | Rating: 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 2008 | Member Level: Gold | Rating: 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
|