what is the xact error that you get ?|||i don't get an error it just will not execute the executeNonQuery command. I wish i got an error then i could fix it.|||Does it throw an exception? What's the message from exception handler??|||try doing a repsonse.write of your sqlInsert to see how its building up. also i'd recommend using parameterized queries..
Dim sqlInsert As String
Dim ssn As String
Dim ssnDash As String
Dim mma As String
Dim position As String
Dim subject As String
Dim mmaCheck As String
Dim subjectCheck As String
Dim bothCheck As String
Dim otherCheck As String
Dim flag As Boolean = False
Dim added As Boolean = FalseTry
If txtSSN.Text <> "" Then
ssn = txtSSN.Text
ssnDash = ssn.Substring(0, 3) & "-" & ssn.Substring(3, 2) & "-" & ssn.Substring(5, 4)
End Ifmma = dlMMA.SelectedValue.ToString
position = dlPosition.SelectedValue.ToString
subject = dlMajor.SelectedValue.ToStringCatch ex As Exception
Response.Write("Please fill in all fields")
End TryotherCheck = mma & subject
Dim dr As DataRow
For Each dr In dsMajor.Tables("List_Of_MMA").Rows
If mma = dr.Item("mma").ToString And subject = dr.Item("Subject").ToString Then
mmaCheck = dr.Item("MMA").ToString
subjectCheck = dr.Item("Subject").ToString
flag = True
bothCheck = mmaCheck & subjectCheck
End If
NextIf flag = False Then
Response.Write("Didn't Work")
Else
sqlInsert = "INSERT INTO Student_Major(SSN, MMA, Subject, Position) Values('"
sqlInsert += ssnDash & "','"
sqlInsert += mmaCheck & "','"
sqlInsert += subjectCheck & "','"
sqlInsert += position & "')"Dim com As OleDbCommand = New OleDbCommand(sqlInsert, myConnection)
Try
myConnection.Open()
com.ExecuteNonQuery()added = True
Catch ex As Exception
Response.Write(sqlInsert)
Finally
myConnection.Close()
End Try'If added = True Then
Response.Write("New Major, Minor, or Area added: " & subject)
'End If
End If
hth|||Ok thanks for the replies we fixed the problem by changing the query to this
sqlInsert = "INSERT INTO Student_Major Values ('"
sqlInsert += ssnDash & "','"
sqlInsert += mma & "','"
sqlInsert += subject & "','"
sqlInsert += position & "')"
Where can i find information on parameterized queries?|||http://aspnet101.com/aspnet101/tutorials.aspx?id=1
No comments:
Post a Comment