本文介绍了检查我的数据库中是否存在文本C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嘿伙计们,任何人都可以帮我查一下数据库中是否有文字 这就是我现在写的内容 < connstring = SERVER = 188.121.43.9; PORT = 3306; DATABASE = mydbname; UID = mydbusername; PASSWORD = s1996;; MySqlConnection conn = new MySqlConnection(connstring); MySqlCommand command = conn.CreateCommand(); command.CommandText =从dbtable中选择全部; > 这就是我的数据库的样子 < uname upass test 1900 test2 1999 > i有textbox1 我想要的是 例如: chek如果textbox1.text存在于列uname show MessageBox.Show(存在) 我尝试过: 嘿伙计们,任何人都可以帮我检查数据库中是否存在文本这就是我现在写的内容< connstring =SERVER = 188.121.43.9; PORT = 3306; DATABASE = mydbname; UID = mydbusername; PASSWORD = s1996;; MySqlConnection conn = new MySqlConnection(connstring); MySqlCommand command = conn.CreateCommand(); command.CommandText =从dbtable中选择全部; > 这就是我的数据库看起来像 < uname upass test 1900 test2 1999 > i有textbox1 我想要的是例如: chek如果textbox1.text存在于列uname上显示MessageBox.Show(exists) 解决方案 - 我使用了ExecuteScalar方法,因为它需要更少的代码和更少的资源 - 请参阅SqlCommand.ExecuteScalar Method(System.Data.SqlClient) [ ^ ] - 我检查确保在尝试使用该值之前在comboBox上实际选择了某些内容。 hey guys can anyone help me to check if a text exist in databasethats what im writting at this moment<connstring = "SERVER=188.121.43.9;PORT=3306;DATABASE=mydbname;UID=mydbusername;PASSWORD=s1996;"; MySqlConnection conn = new MySqlConnection(connstring); MySqlCommand command = conn.CreateCommand(); command.CommandText = "Select all from dbtable";>this is how my DB looks like<uname upasstest 1900test2 1999>i have textbox1what i want isfor example : chek if textbox1.text exist at column uname show MessageBox.Show("exist")What I have tried:hey guys can anyone help me to check if a text exist in databasethats what im writting at this moment<connstring = "SERVER=188.121.43.9;PORT=3306;DATABASE=mydbname;UID=mydbusername;PASSWORD=s1996;"; MySqlConnection conn = new MySqlConnection(connstring); MySqlCommand command = conn.CreateCommand(); command.CommandText = "Select all from dbtable";>this is how my DB looks like<uname upasstest 1900test2 1999>i have textbox1what i want isfor example : chek if textbox1.text exist at column uname show MessageBox.Show("exist") 解决方案 - I've used the ExecuteScalar method as it requires less code and fewer resources - see SqlCommand.ExecuteScalar Method (System.Data.SqlClient)[^] - I check to ensure there is something actually selected on the comboBox before attempting to use the value. 这篇关于检查我的数据库中是否存在文本C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 21:42