 |
| ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application . |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 16th, 2006, 02:30 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
SQL DBConnection problem
Hi people, I am using vs web developer and sql express,
I attempt to enter the data into the database without the use of datagrid/update procedure
I am using the following code ON BUTTON CLICK but the compiler throws an error every time.
Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim DBConn As SqlConnection
Dim DBAdd As New SqlCommand
DBConn = New SqlConnection("Server =.\SQLExpress;AttachDbFile=|DataDirectory|\ASPNETD B.MDF;Database =dbASPNETDB.MDF; User Instance=True; Trusted_Connection = Yes;")
DBAdd.CommandText = "Insert into Rates" _
& "(RatesCategory) " _
& "values" _
& "'" & Replace (txtRate.Text, "'" "''")_
& "')";
DBAdd.Connection = DBConn
DBAdd.Connection.Open()
DBAdd.ExecuteNonQuery()
Response.Redirect("./SuccessLogin.aspx")
End Sub
Appreciate that
MDM
|
|

March 16th, 2006, 04:34 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
It would be really useful if you posted the error message from the compiler.
Otherwise, we're in the same darkness as you are.... ;)
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 20th, 2006, 10:14 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I will get the error message asap. In a mean while, I think the problme may lie in the syntax here
DBAdd.CommandText = "Insert into Rates" _
& "(RatesCategory) " _
& "values" _
& "'" & Replace (txtRate.Text, "'" "''")_
& "')";
it doesn like values line and replace line, I have tried insert with no succes either.
thanks for attempt
mdm
|
|

March 20th, 2006, 01:22 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Maybe you need to add a space here and there before and after some field names, like Values.
However, without the error message, that's just a guess....
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

April 5th, 2006, 04:02 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
here is the code:
Insert into the database
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cnn As Data.SqlClient.SqlConnection = _ <--- This is where the compiler stumbles
New Data.SqlClient.SqlConnection("DataSource = (local);" & _
"InitialCatalog = Rates; Integrated Security = SSPI")
Dim StrQuery As String = "INSERT INTO Rates" & _
"(1, 2) " & _
"VALUES('" & CStr(Session("RC")).Replace("'", "''") & _
"', " & CStr(Session("UC")).Replace("'", "''") & ")"
Dim cmd As New Data.SqlClient.SqlCommand(StrQuery, cnn)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cnn.Close()
Error message:
Keyword not supported: 'datasource'.
thanx
|
|

April 5th, 2006, 04:33 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Also, the connection to the database make me cry. I am 2 months into dot net2.0 and this is still blurry. Please, drop a coule of lines re the above code or suggest a code that actually works! I got so many book at my's but the code is bugged and also is a little f...sorry, got carried away. The project takes its toll
mdm
|
|

April 7th, 2006, 11:58 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar, ta for the link. Been there dozen of times.
my connection string fits the description; however, this datasource error message is out of picture. Does the fact that the database is on in the file system as opposite on the sql server any difference?
please come back to me on that
mdm
|
|

April 7th, 2006, 12:10 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Did you change the connection string you posted here after you visited ConnectionStrings.com??
If so, how does your current connection string look like?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

April 7th, 2006, 12:59 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
the above string is the same
Insert into the database
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cnn As Data.SqlClient.SqlConnection = _ <--- This is where the compiler stumbles
New Data.SqlClient.SqlConnection("DataSource = (local);" & _
"InitialCatalog = Rates; Integrated Security = SSPI")
Dim StrQuery As String = "INSERT INTO Rates" & _
"(1, 2) " & _
"VALUES('" & CStr(Session("RC")).Replace("'", "''") & _
"', " & CStr(Session("UC")).Replace("'", "''") & ")"
Dim cmd As New Data.SqlClient.SqlCommand(StrQuery, cnn)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cnn.Close()
Error message:
Keyword not supported: 'datasource'.
Man, cant get my head around it. once gain, the file is on the local file system - IIS /wwroot folder.
thanx for blitz answ
mdm
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| SQL problem |
MArk_dB |
BOOK: Beginning ASP 3.0 |
1 |
December 16th, 2007 07:33 AM |
| sql problem |
shrisangeeta |
Classic ASP Databases |
2 |
May 24th, 2006 09:58 AM |
| SQL problem |
Lexus |
SQL Language |
2 |
January 20th, 2005 09:25 AM |
| SQL problem |
Clive Astley |
Access VBA |
4 |
October 19th, 2004 10:42 AM |
| SQL Problem |
tjw |
Access |
1 |
November 12th, 2003 09:22 PM |
|
 |