User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 392,322 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,768 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting

Error connecting to database

Join Date: Nov 2005
Posts: 23
Reputation: Reham Ejaz is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Reham Ejaz Reham Ejaz is offline Offline
Newbie Poster

Error in updating database

  #5  
Jan 30th, 2006
There wasnt any problem with the settings. Now I have succeeded in updating simple database via OleDBDataAdapter and OleDbCommandBuilder objects but the same code is not working when I am using to update too many columns. Actually I cant figure out the error in my following code.


dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\wwwroot\website\visitor.mdb")
Dim cmd As OleDbDataAdapter
Dim ds As New DataSet()
Dim dr As DataRow

sub submit_clicked(Sender as object, e as Eventargs)

		dim i,j as integer
   		dim str as string
		'dim countrystr,  tourstr as string
   		dim param(7) as string
   		dim flag as boolean=true

			
'Inserting values from text boxes into a string array

   		j=0
     		for i=0 to panel1.controls.count-1
          	if panel1.controls(i).GetType Is GetType(textbox) then
           		str=Ctype(panel1.controls(i),textbox).text
                	if str <> "" then
                     		param(j)=str
                	else
                    		flag=false
                    	label1.text="forgot to enter  value for " & panel1.controls(i).id
                	end if
               		j=j+1
           	end if
    		next
		
   		if not flag then
     			exit sub
   		end if


		try
 			cmd = New OleDbDataAdapter(New OleDbCommand("select * from visitors",conn))
			Dim comb As OleDbCommandBuilder = New OleDbCommandBuilder(cmd)
			conn.Open()
			cmd.fill(ds,"visitorinfo1")
			dr = ds.Tables("visitors").NewRow()

		catch ex as exception
			label1.text="Error in updating database"
		end try

'Entering values in datarow from textboxes
                
		dr("Name") = param(0)
		dr("Email") = param(1)

		if rdbgender.SelectedIndex = 0
			dr("Gender") = "Male"
		else
			dr("Gender") = "Female"
		end if

		dr("Age") = param(2)
		dr("Address") = param(3)
		dr("Phone No") = param(4)
		countrystr = ddlcountry.SelectedItem.Text
		dr("Country") = countrystr
		dr("Tour Type") = rdbtour.SelectedItem.Text
		tourstr = lbdetails.SelectedItem.Text
		dr("Tour Detail") = tourstr
                
		dr("Custom Tour") = param(5)
		dr("No of Travellers") = param(6)
		

		ds.Tables("visitors").Rows.Add(dr)
		
		cmd.Update(ds, "visitors")
		label1.text="database updated"

	end sub

Name, Age, ...... are the names of columns in database table in Access

ddlcountry and ddldetails are the id's of dropdownlist controls
rdbtour is id of the radiobutton control in html part of page.


Now with this code I am having problem on the line

cmd.Update(ds, "visitor")

Error is
Syntax error in INSERT INTO statement

If anyone can figureout the error in this code plz let me know. I will be thankful.
Reply With Quote  
All times are GMT -4. The time now is 10:47 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC