VB.NET and SQL Server - How to Update data in SQL Server Database using Vb.net.

Published: 05 June 2020
on channel: VB Programming Lab
34
0

VB.NET and SQL Server - How to Update data in SQL Server Database using Vb.net
#sqlserver #vb.net #update

Code:-

Public sqlconn As New SqlConnection
Dim connstring = ""
sqlconn.ConnectionString = connstring

Dim dtStudent As New DataTable
Dim cmdStudent As New SqlCommand("USP_Select_StudentData", sqlconn)
cmdStudent.Parameters.Add("@StudentID", SqlDbType.Int).Value = txtSearchStuID.Text
cmdStudent.CommandType = CommandType.StoredProcedure
Dim daStudent As New SqlDataAdapter
daStudent.SelectCommand = cmdStudent
daStudent.Fill(dtStudent)
txtStudentID.Text = dtStudent.Rows(0).Item(0).ToString
txtStudentName.Text = dtStudent.Rows(0).Item(1).ToString
txtUniversity.Text = dtStudent.Rows(0).Item(2).ToString
txtCourse.Text = dtStudent.Rows(0).Item(3).ToString
txtGender.Text = dtStudent.Rows(0).Item(4).ToString
txtAge.Text = dtStudent.Rows(0).Item(5).ToString


Dim cmdUpdateStdData As New SqlCommand("USP_Update_StudentData", sqlconn)
cmdUpdateStdData.CommandType = CommandType.StoredProcedure
cmdUpdateStdData.Parameters.Add("@StudentID", SqlDbType.Int).Value = txtSearchStuID.Text
cmdUpdateStdData.Parameters.Add("@StudentName", SqlDbType.VarChar).Value = txtStudentName.Text
cmdUpdateStdData.Parameters.Add("@University", SqlDbType.VarChar).Value = txtUniversity.Text
cmdUpdateStdData.Parameters.Add("@Course", SqlDbType.VarChar).Value = txtCourse.Text
cmdUpdateStdData.Parameters.Add("@Gender", SqlDbType.VarChar).Value = txtGender.Text
cmdUpdateStdData.Parameters.Add("@Age", SqlDbType.Int).Value = txtAge.Text
sqlconn.Open()
cmdUpdateStdData.ExecuteNonQuery()
sqlconn.Close()
MsgBox("Record Updated", MsgBoxStyle.OkOnly, "Student form")


Watch video VB.NET and SQL Server - How to Update data in SQL Server Database using Vb.net. online without registration, duration hours minute second in high quality. This video was added by user VB Programming Lab 05 June 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 34 once and liked it 0 people.