ado.net中使用vb.net的奇怪工作流程 [英] strange workflow in ado.net with vb.net
本文介绍了ado.net中使用vb.net的奇怪工作流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Professionals,
Hello Professionals,
i had assigned a assignment for insert,update, delete operation in a table for my student. he had done this assignment fine. but his code made me crazy that he wrote update code like below
Working sample:
Public Function Toeditdetails(ByVal item As Boolean)
If item = True Then
Dim con As SqlConnection
Dim retval As Integer
con = New SqlConnection(conn)
con.Open()
Dim cmd As SqlCommand
cmd = New SqlCommand("updatelogin", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@username", SqlDbType.VarChar, 100)).Value() = TextBox1.Text.Trim()
cmd.Parameters.Add(New SqlParameter("@user_password", SqlDbType.VarChar, 30)).Value() = TextBox2.Text.Trim()
cmd.Parameters.Add(New SqlParameter("@nameofuser", SqlDbType.VarChar, 100)).Value() = TextBox3.Text.Trim()
cmd.Parameters.Add(New SqlParameter("@contact_no", SqlDbType.VarChar, 10)).Value() = TextBox4.Text.Trim()
cmd.Parameters.Add(New SqlParameter("@email", SqlDbType.VarChar, 100)).Value() = TextBox5.Text.Trim()
cmd.Parameters.Add(New SqlParameter("@joiningdate", SqlDbType.Date)).Value() = DateTimePicker1.Value
cmd.Parameters.Add(New SqlParameter("@usergroup_id", SqlDbType.Int)).Value() = SelectedID(ComboBox1.Text)
If item = True Then
cmd.Parameters.Add(New SqlParameter("@id", SqlDbType.Int)).Value() = Label9.Text.Trim()
End If
Dim da As SqlDataAdapter
da = New SqlDataAdapter(cmd)
Dim dst As New DataSet
da.Fill(dst)
If dst.Tables.Count > 0 Then
DataGridView1.DataSource = dst.Tables(0)
End If
If Not cmd Is Nothing Then
cmd.Dispose()
End If
End If
End Function
Note there is no ExecuteNonQuery() method for his SqlCommand object and he didn't call this method in entire project. when i call this function result still updating... how its happen? anyone genius can you explain what's going on above statement? any help would be appreciated
问候并感谢
Regards and Thanks
推荐答案
原因它发生的原因是你的学生正在使用仍然执行代码的数据集和SqlDataAdapter(da.Fill)。通常它们用于选择数据,您可以使用SqlCommand进行更新/插入,但这种方法仍然有效。
The reason it happens is because your student is using a DataSet and SqlDataAdapter which still executes code (da.Fill). Normally they are used for selecting data and you would use the SqlCommand for updating/inserting but this method can still work.
这篇关于ado.net中使用vb.net的奇怪工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文