Loading ...

Insert Query not working. the insert command is executed successfully but a blank row is added in table in MySQL database

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  data access   » Insert Query not working. the insert command is executed successfully but a blank row is added in table in MySQL database

Insert Query not working. the insert command is executed successfully but a blank row is added in table in MySQL database

Posts under the topic: Insert Query not working. the insert command is executed successfully but a blank row is added in table in MySQL database

Posted: 12/4/2011

Lurker 5  points  Lurker
  • Joined on: 12/4/2011
  • Posts: 1

Tried all the methods to add parameters but still the rows in dabase are blank. By default they take null values in db

Code

Dim connStr As String = ConfigurationManager.ConnectionStrings("MySQLConnStr").ConnectionString
Dim con As Odbc.OdbcConnection = New Odbc.OdbcConnection(connStr)
Dim myReader As Odbc.OdbcDataReader
Dim count As Integer
Dim varUserId As String
Dim min As Integer
Dim sec As Integer


Try
Dim queryStr1 As String
queryStr1 = "select count(userId) from tblSurveyUserMaster"

Dim command1 As New Odbc.OdbcCommand(queryStr1, con)
con.Open()
myReader = command1.ExecuteReader()
If myReader.HasRows Then
count = myReader(0)
count = count + 1
min = Minute(Now)
sec = Second(Now)
varUserId = txtName.Text + count.ToString + min.ToString + sec.ToString
'MsgBox("User Id : " + varUserId)

End If




''*************************************************************************************************************************************
Dim queryStr As String
Dim param = New Odbc.OdbcParameter
param.ParameterName = "@userId"
param.Value = varUserId

queryStr = "Insert into tblSurveyUserMaster values (@id,@userId,@userName,@college,@email,@university,@collegeUnder,@occupation,@yearInfo,@numProjects)"
Dim command As New OdbcCommand(queryStr, con)
'command.Parameters.Add(New Odbc.OdbcParameter("@id", OdbcType.Int)).Value = 1
command.Parameters.Add(param)
'command.Parameters.Add(New Odbc.OdbcParameter("@userId", OdbcType.VarChar, 225)).Value = varUserId
'command.Parameters("@userId").Value = varUserId
'MsgBox("User Id : " + varUserId)
command.Parameters.Add(New Odbc.OdbcParameter("@userName", OdbcType.VarChar, 45)).Value = txtName.Text
MsgBox("User Id : " + txtName.Text)
command.Parameters.Add(New Odbc.OdbcParameter("@college", OdbcType.VarChar, 45)).Value = txtCollege.Text
command.Parameters.Add(New Odbc.OdbcParameter("@email", OdbcType.VarChar, 45)).Value = txtEmailId.Text
command.Parameters.Add(New Odbc.OdbcParameter("@university", OdbcType.VarChar, 45)).Value = txtUniversity.Text
command.Parameters.Add(New Odbc.OdbcParameter("@collegeUnder", OdbcType.VarChar, 45)).Value = ddlCollege.SelectedItem.ToString
command.Parameters.Add(New Odbc.OdbcParameter("@occupation", OdbcType.VarChar, 45)).Value = ddlOccupation.SelectedItem.ToString
If ddlOccupation.SelectedItem.ToString = "Job" Or ddlOccupation.SelectedItem.ToString = "Faculty" Then
command.Parameters.Add(New Odbc.OdbcParameter("@yearInfo", OdbcType.VarChar, 45)).Value = txtInfo.Text
'MsgBox("User Id : " + txtInfo.Text)
Else
command.Parameters.Add(New Odbc.OdbcParameter("@yearInfo", OdbcType.VarChar, 45)).Value = ddlYear.SelectedItem.ToString
'MsgBox("User Id : " + ddlYear.SelectedItem.ToString)
End If
'con.Open()
command.ExecuteNonQuery()
con.Close()
MsgBox("Inserted Succefully")

Catch ex As Exception
MsgBox("Error : " + ex.ToString)

End Try

 


Page 1 of 1 (1 items)