需要帮助在mysql表中插入值 [英] Need help in inserting value to mysql table
本文介绍了需要帮助在mysql表中插入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我有以下表格
表1:用户名,密码
表2:用户名,密码,状态
现在我想一次向表插入值,并想检查数据是否插入到table2成功然后状态应该变为1否则0
请告诉我该怎么做
谢谢
解决方案
您可以使用MySqlConnection和MySqlCommand对数据库执行insert语句。有关示例,请查看 MySqlCommand [ ^ ]
增加:
...
Dim i 作为 整数 = cmd1.ExecuteNonQuery()
cmd1.CommandText = UPDATE表SET状态= @NewStatus
Dim statusparam AS MySqlParameter = new MySqlParameter( @ NewStatus,MySqlDbType。 Long < /跨度>);
cmd1.Parameters.Add(statusparam)
如果(i> 0 )然后
statusparam.Value = 1
其他
statusparam.Value = 0
结束 如果
i = cmd1.ExecuteNonQuery()
con.Close()
Hi all
I have the below tables
Table1: username, password
Table2: username, password, status
Now i want to insert value to this to tables at a time and want to check if data inserted to table2 successfully then status should become 1 else 0
please tell me how to do that
Thank you
解决方案
You can use MySqlConnection and MySqlCommand to execute the insert statements to the database. For an example, have a look at MySqlCommand[^]
Addition:
... Dim i As Integer = cmd1.ExecuteNonQuery() cmd1.CommandText = "UPDATE Table SET Status = @NewStatus" Dim statusparam AS MySqlParameter = new MySqlParameter("@NewStatus", MySqlDbType.Long); cmd1.Parameters.Add(statusparam ) If (i > 0) Then statusparam.Value = 1 Else statusparam.Value = 0 End If i = cmd1.ExecuteNonQuery() con.Close()
这篇关于需要帮助在mysql表中插入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文