Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 16th, 2006, 02:30 PM
MDM MDM is offline
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

Reply With Quote
  #2 (permalink)  
Old March 16th, 2006, 04:34 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #3 (permalink)  
Old March 20th, 2006, 10:14 AM
MDM MDM is offline
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #4 (permalink)  
Old March 20th, 2006, 01:22 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #5 (permalink)  
Old April 5th, 2006, 04:02 PM
MDM MDM is offline
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #6 (permalink)  
Old April 5th, 2006, 04:33 PM
MDM MDM is offline
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #7 (permalink)  
Old April 5th, 2006, 04:35 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Take a look here: http://www.connectionstrings.com/ for proper syntax of your connection string.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #8 (permalink)  
Old April 7th, 2006, 11:58 AM
MDM MDM is offline
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #9 (permalink)  
Old April 7th, 2006, 12:10 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
Reply With Quote
  #10 (permalink)  
Old April 7th, 2006, 12:59 PM
MDM MDM is offline
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:38 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.