db not able to catch the data
-
hi there , i am having problems getting my data to the db .. there are no errors displaying .. its just that data wont go in ...
Dim a As String Dim b As String a = TextBox1.Text Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\temp\db1.mdb") Dim strSQL As String = "INSERT INTO Table1 (yo,yoyo) VALUES (a,a) where user = '" + TextBox2.Text + "'" 'Dim strSQL As String = "INSERT INTO Settins (PhotoUpload) VALUES (@img) WHERE UserID = '" + rId + "'" Dim cmd As New OleDbCommand(strSQL, cnn) Try cnn.Open() cmd.ExecuteNonQuery() Catch ex As Exception 'lb_Msg.Text = ex.Message Finally If Not cmd Is Nothing Then cmd.Dispose() End If If Not cnn Is Nothing Then cnn.Close() cnn.Dispose() End If End Try End Sub
-
hi there , i am having problems getting my data to the db .. there are no errors displaying .. its just that data wont go in ...
Dim a As String Dim b As String a = TextBox1.Text Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\temp\db1.mdb") Dim strSQL As String = "INSERT INTO Table1 (yo,yoyo) VALUES (a,a) where user = '" + TextBox2.Text + "'" 'Dim strSQL As String = "INSERT INTO Settins (PhotoUpload) VALUES (@img) WHERE UserID = '" + rId + "'" Dim cmd As New OleDbCommand(strSQL, cnn) Try cnn.Open() cmd.ExecuteNonQuery() Catch ex As Exception 'lb_Msg.Text = ex.Message Finally If Not cmd Is Nothing Then cmd.Dispose() End If If Not cnn Is Nothing Then cnn.Close() cnn.Dispose() End If End Try End Sub
lhahehal wrote:
Dim strSQL As String = "INSERT INTO Table1 (yo,yoyo) VALUES (a,a) where user = '" + TextBox2.Text + "'"
This is telling the database to insert in to the columns called
yo
andyoyo
the value in the column calleda
. Is that what you want? I suspect not because earlier in the code you have:lhahehal wrote:
Dim a As String a = TextBox1.Text
I am guessing that what you actually want is the value of the variable a in your VB.NET code. However, the database cannot see that value unless you tell it about it. So you have to construct your query so it does tell it about the value. Next, there is a major security hole in your application that you need to clear up because it is open to a SQL Injection Attack which can compromise your database. You need to read SQL Injection Attacks and Tips on How to Prevent Them[^] ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
-
hi there , i am having problems getting my data to the db .. there are no errors displaying .. its just that data wont go in ...
Dim a As String Dim b As String a = TextBox1.Text Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\temp\db1.mdb") Dim strSQL As String = "INSERT INTO Table1 (yo,yoyo) VALUES (a,a) where user = '" + TextBox2.Text + "'" 'Dim strSQL As String = "INSERT INTO Settins (PhotoUpload) VALUES (@img) WHERE UserID = '" + rId + "'" Dim cmd As New OleDbCommand(strSQL, cnn) Try cnn.Open() cmd.ExecuteNonQuery() Catch ex As Exception 'lb_Msg.Text = ex.Message Finally If Not cmd Is Nothing Then cmd.Dispose() End If If Not cnn Is Nothing Then cnn.Close() cnn.Dispose() End If End Try End Sub
-
Of course there is no errors displaying. You catch the errors and ignore them. You have commented out the only code that would do anything in case of an error. --- b { font-weight: normal; }
-
i have uncomment the exception and it prompts Missing semicolon (;) at end of SQL statement. but i could not see anywhere to insert it as its not java ...
Dim strSQL As String = "INSERT INTO Table1 (yo,yoyo) VALUES (a,a) where user = '" + TextBox2.Text + "'"
Here values(a,a) is completely wrong one. You have to replace this intoValues('" & a & "','" & a & "')"
if the fields are string this code , if this fields are numeric it should beValues(" & a & "," & a & ")"
Regards R.Arockiapathinathan -
Dim strSQL As String = "INSERT INTO Table1 (yo,yoyo) VALUES (a,a) where user = '" + TextBox2.Text + "'"
Here values(a,a) is completely wrong one. You have to replace this intoValues('" & a & "','" & a & "')"
if the fields are string this code , if this fields are numeric it should beValues(" & a & "," & a & ")"
Regards R.Arockiapathinathanhi thx .. it solve the problem ... now i am trying update but seems to hit a different kind of problem .. Server was unable to process request. --> No value given for one or more required parameters.
Dim a As String Dim b As String Dim strSNameFont As String Dim strSNameSize As String Dim strSNameColor As String Dim strNameBold As String Dim strNameItalic As String Dim strnameunderline As String strSNameFont = ddlSNameFont.SelectedValue strSNameSize = ddlSNameSize.SelectedValue strSNameColor = ddlSNameColor.SelectedValue strNameBold = cbNameBold.Checked strNameItalic = cbNameItalic.Checked Dim i As Integer = 1 strnameunderline = "nil" a = TextBox1.Text Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\TDB.mdb") Dim strSQL As String = "UPDATE Settings SET NameFont = '" + strSNameFont + "', FontSize = '" + strSNameSize + _ "', FontColor = '" + strSNameColor + _ "', FBold = '" + strNameBold + _ "', FItalic = '" + strNameItalic + _ "' WHERE UserID='" + TextBox2.Text + "'" Dim cmd As New OleDbCommand(strSQL, cnn) cnn.Open() _**cmd.ExecuteNonQuery()**_ <----- in red cnn.Close() End Sub
-
hi thx .. it solve the problem ... now i am trying update but seems to hit a different kind of problem .. Server was unable to process request. --> No value given for one or more required parameters.
Dim a As String Dim b As String Dim strSNameFont As String Dim strSNameSize As String Dim strSNameColor As String Dim strNameBold As String Dim strNameItalic As String Dim strnameunderline As String strSNameFont = ddlSNameFont.SelectedValue strSNameSize = ddlSNameSize.SelectedValue strSNameColor = ddlSNameColor.SelectedValue strNameBold = cbNameBold.Checked strNameItalic = cbNameItalic.Checked Dim i As Integer = 1 strnameunderline = "nil" a = TextBox1.Text Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\TDB.mdb") Dim strSQL As String = "UPDATE Settings SET NameFont = '" + strSNameFont + "', FontSize = '" + strSNameSize + _ "', FontColor = '" + strSNameColor + _ "', FBold = '" + strNameBold + _ "', FItalic = '" + strNameItalic + _ "' WHERE UserID='" + TextBox2.Text + "'" Dim cmd As New OleDbCommand(strSQL, cnn) cnn.Open() _**cmd.ExecuteNonQuery()**_ <----- in red cnn.Close() End Sub
-
That means that one or more of the names in the query does not exist in the database. --- b { font-weight: normal; }
may be the tablename Settings make some problem. try like this
update [settings] ....
And also from ur code, all fields are string. Is it correct? if any of the fields are non string then remove single codes both sides. Regards R.Arockiapathinathan -
may be the tablename Settings make some problem. try like this
update [settings] ....
And also from ur code, all fields are string. Is it correct? if any of the fields are non string then remove single codes both sides. Regards R.Arockiapathinathan -
yup i checked through the database , all are string , i did not want to update the ole object so i left it out ... i tried [setting] but it prompts the same error ...
double check the field names carefully No value given for one or more required parameters Normally this error will comes when field names are wrong Regards R.Arockiapathinathan
-
double check the field names carefully No value given for one or more required parameters Normally this error will comes when field names are wrong Regards R.Arockiapathinathan
hmm the strange thing is when i query from access its fine .. then i tried retyping it .. and suddenly it works ... strange strange now i face another problem ...
Input string was not in a correct format. Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 151: Line 152: 'set setting checkbox Line 153: cbNameBold.Checked = StoreSetting.NameBold <-- red
namebold is a get/set method ... -
hmm the strange thing is when i query from access its fine .. then i tried retyping it .. and suddenly it works ... strange strange now i face another problem ...
Input string was not in a correct format. Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 151: Line 152: 'set setting checkbox Line 153: cbNameBold.Checked = StoreSetting.NameBold <-- red
namebold is a get/set method ...Checked property will accept only boolean value true or false. so your property should be return true or false instead of string. Regards R.Arockiapathinathan
-
Checked property will accept only boolean value true or false. so your property should be return true or false instead of string. Regards R.Arockiapathinathan