本文介绍了如何测试数据库中是否存在值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我该如何检查res4是否找到了值。如果我粘贴textbox4不存在的值,我在第一行有错误:附加信息:如果对象打开,则不允许操作。有什么问题? cnn.ConnectionString =driver = {SQL Server}; &安培; server = xxx.xxx.xx; uid = xx; pwd = xxxx +; database = xxxxx 我有什么试过: Private Sub TextBox4_TextChanged(sender As Object,e As EventArgs)处理TextBox4.TextChanged cnn.ConnectionString =driver = {SQL Server}; &安培; server = xxx.xxx.xx; uid = xx; pwd = xxxx +; database = xxxxx 尝试 cnn.Open() Catch MsgBox(Připojeníkdatabázisenezdařilo。,Chyba)结束尝试 'Overeni zda pripojeni probehlo OK 如果cnn.State = 1则$ b $b'Automatickévyhledáníčíslapílulekóduoperace尝试如果TextBox4.Text.Length = 9则 res4 = cnn.Execute(SELECT VKmenStavVC.RegCis From TabVyrCS LEFT OUTER JOIN TabKmenZbozi VKmenStavVC ON VKmenStavVC.ID =(SELECT TabStavSkladu.IDKmenZbozi FROM TabStavSkladu WHERE TabStavSkladu.ID = TabVyrCS.IDStavSkladu)LEFT OUTER JOIN TabVyrCS_EXT WITH(NOLOCK)ON TabVyrCS_EXT.ID = TabVyrCS.ID WHERE TabVyrCS.Nazev1 ='& TextBox1.Text &')如果cnn.ExecuteScalar<> 0然后 Dim registracni4 As String = res4.GetString registracni4 = registracni4.Replace(vbCr,)如果registracni4 = TextBox11.Text那么 TextBox15.Text =OK TextBox10.Text = registracni4 Else TextBox15.Text =NOK MsgBox(Nesouhlasíčíslodíluvýrobníoperací!,Chyba)结束如果 其他 MsgBox(Hodnota nenalezena,Chyba)结束如果结束如果捕获 cnn .Close() MsgBox(Napojenídotabulkysenezdařilo,Chyba) TextBox4.Clear()返回结束尝试否则 cnn.Clos e()结束如果结束子 解决方案 这篇关于如何测试数据库中是否存在值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-13 16:01