[英]Problem insert textbox in database VB.NET
I have a problem with insert textbox into the database.我在将文本框插入数据库时遇到问题。 I just want to create a user with the textbox and so my question is how to add the data from the textbox into the User table of my database ?
我只想用文本框创建一个用户,所以我的问题是如何将文本框中的数据添加到我的数据库的用户表中?
I redid all the code and found a simpler method but I have the following error showing "System.Data.SqlClient.SqlException: 'Invalid' User 'object name.'我重新编写了所有代码并找到了一个更简单的方法,但出现以下错误,显示“System.Data.SqlClient.SqlException: 'Invalid' User 'object name.' System .Data.SqlClient.SqlException: 'Invalid' User 'object name.'
System .Data.SqlClient.SqlException: '无效' 用户 '对象名称。 " in the row rs = SqlCommande.ExecuteReader()
" 在行rs = SqlCommande.ExecuteReader()
Dim CnxAppli As String = "Server=" & My.Settings.nomServeur & "; DataBase= " & My.Settings.nomBDD & "; Uid=" & My.Settings.idUser & "; Pwd=" & My.Settings.mdp & "; Integrated Security=SSPI;"
Dim sqlConnect As New SqlConnection
sqlConnect.ConnectionString = CnxAppli
Dim SqlReq As String = "insert into Utlisateur (nom, prenom, tel, mail, poste, login, mdp) values ('" & tbNom.Text & "', '" & tbPrenom.Text & "', '" & tbTel.Text & "', '" & tbMail.Text & "', '" & tbPoste.Text & "', '" & tbLogin.Text & "', '" & tbMdp.Text & "')"
Dim SqlCommande = New SqlCommand(SqlReq, sqlConnect)
'SqlCommande.CommandText = SqlReq
'SqlCommande.Connection = sqlConnect
sqlConnect.Open()
Dim rs As SqlDataReader
rs = SqlCommande.ExecuteReader()
rs.Close()
sqlConnect.Close()
GestionUtilisateurs.Show()
Me.Close()
I managed to find a solution.我设法找到了解决方案。 For those who want the solution:
对于那些想要解决方案的人:
Dim CnxAppli As String = "Server=" & My.Settings.nomServeur & "; DataBase= " & My.Settings.nomBDD & "; Uid=" & My.Settings.idUser & "; Pwd=" & My.Settings.mdp & "; Integrated Security=SSPI;"
Dim sqlConnect As New SqlConnection
sqlConnect.ConnectionString = CnxAppli
Dim cmSQL As SqlCommand
Dim strSQL = "insert into utilisateur(nom, prenom, tel, mail, poste, login, mdp) values('" & tbNom.Text & "','" & tbPrenom.Text & "','" & tbTel.Text & "','" & tbMail.Text & "','" & tbPoste.Text & "','" & tbLogin.Text & "','" & tbMdp.Text & "')"
cmSQL = New SqlCommand(strSQL, sqlConnect)
Dim DataAdapter As New SqlDataAdapter(cmSQL)
Dim cmBuilder As New SqlCommandBuilder(DataAdapter)
Dim DataSet As New DataSet()
Dim DataTable As New DataTable
sqlConnect.Open()
cmSQL.Connection = sqlConnect
DataAdapter.Fill(DataSet, "utilisateur")
DataTable = DataSet.Tables("utilisateur")
'cmSQL = New SqlCommand(strSQL, cnSQL)
'cmSQL.ExecuteNonQuery()
sqlConnect.Close()
GestionUtilisateurs.Show()
Me.Close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.