Results 1 to 8 of 8

Thread: [RESOLVED] AccessDataSource1 is not declared

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Resolved [RESOLVED] AccessDataSource1 is not declared

    in my code file i write
    Code:
    AccessDataSource1.insert()
    it says AccessDataSource1 is not declared

    although i have
    Code:
     <asp:AccessDataSource ID="AccessDataSource1" runat="server"  DataFile="~/db/container.accdb.mdb" InsertCommand="insert into users  (@txt_name.text ,@txt_position.text,@txt_cname.text,@txt_address.text,@txt_city.text,@txt_state,@dropdownlist1.selecteditem.text,@txt_telephone.text,@txt_telefax.text,@txt_email.text,@txt_webaddress.text )">
                                </asp:AccessDataSource>
    in my .aspx page
    There is no achievement without goals

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Re: AccessDataSource1 is not declared

    Probably need a bit more than this to go no. The error suggests that
    Code:
    <asp:AccessDataSource ID="AccessDataSource1" runat="server"  DataFile="~/db/container.accdb.mdb" InsertCommand="insert into users  (@txt_name.text ,@txt_position.text,@txt_cname.text,@txt_address.text,@txt_city.text,@txt_state,@dropdownlist1.selecteditem.text,@txt_telephone.text,@txt_telefax.text,@txt_email.text,@txt_webaddress.text )">
                                </asp:AccessDataSource>
    is out of scope. where in the marku p have you placed this?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: AccessDataSource1 is not declared

    ok i m posting few more lines after this
    Code:
    			</div>
    <br><br><br><br><br><br><br><br><br><br>
                                <asp:AccessDataSource ID="AccessDataSource1" runat="server"  DataFile="~/db/container.accdb.mdb" InsertCommand="insert into users  (@txt_name.text ,@txt_position.text,@txt_cname.text,@txt_address.text,@txt_city.text,@txt_state,@dropdownlist1.selecteditem.text,@txt_telephone.text,@txt_telefax.text,@txt_email.text,@txt_webaddress.text )">
                                </asp:AccessDataSource>
                                <br>
    											<div class="right_txt_space_accm">
    											<table width="100%" border="0" cellspacing="0" cellpadding="0">
    											  <tr>
    												<td width="50%" align="left"><strong></strong>
                                                        <asp:CheckBox ID="CheckBox1" Text=agree runat="server" /><strong>I agree with above terms.</strong></td>
    												<td width="50%" align="left"><strong></strong>
                                                        <asp:Button ID="btn_submitt" runat="server" Text="Submit" /></td>
    											  </tr>
    											</table>
    										</form>
    										</div>
     
     
     
     
     
    							<!-- end of meeting details-->
    							<div class="space">
                                    
                                </div>
    							<div class="right_body_footer clr">
    								<div class="rgt_footer_left_txt"></div>
    								
    							</div>
    						</div>
    						
    					</div>
    				</div>
    			</div>
    			<!-- end of root body-->
    		</div>
    		<!-- footer-->
    		<div class="wrapper_footer clr">
    		</div>
    		<!-- end of footer-->
    	</div>
    	<!-- bottom bar -->
    	<div class="wrapper_bottom_bar clr">
    		<div class="bottom_txt">Copyright  ©  2010 GFLN - Global Freight Logistics Network. All rights reserved. </div>
    	</div>
    	<!-- end of bottom bar-->
    </div>
    </body>
    </html>
    do let me know if need further
    There is no achievement without goals

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: AccessDataSource1 is not declared

    Access again
    How and where are you declaring your insert parameters?
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: AccessDataSource1 is not declared

    on code behind of submitt button i write this

    Code:
     Protected Sub btn_submitt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_submitt.Click
            '    InsertCommand = "insert into users  (@txt_name.text ,@txt_position.text,@txt_cname.text,@txt_address.text,@txt_city.text,@txt_state,@dropdownlist1.selecteditem.text,@txt_telephone.text,@txt_telefax.text,@txt_email.text,@txt_webaddress.text )"
            Try
                'insert into users(Name,position ,[company name],Address,city,state,country,telephone,telefax,email,webaddress ) values  ('asdas' ,'sadas','sadas ','sadasd' ,'sadas','sadasd','Bosnia And Herzegowina', 'asda','sada' ,'asdasd' 
                Me.AccessDataSource1.InsertCommand = "insert into users(Name,position ,[company name],Address,city,state,country,telephone,telefax,email,webaddress )values  ('" & Me.txt_name.Text & "' ,'" & Me.txt_position.Text & "','" & Me.txt_cname.Text & " ','" & Me.txt_address.Text & "' ,'" & Me.txt_city.Text & "','" & Me.txt_state.Text & "','" & Me.ddl_Country.SelectedItem.Text & "', '" & Me.txt_Telephone.Text & "','" & Me.txt_telefax.Text & "' ,'" & Me.txt_email.Text & "' ,'" & Me.txt_webaddress.Text & "') "
    
                AccessDataSource1.Insert()
            Catch ex As Exception
                'MsgBox(ex.ToString())
    
            End Try
    
    
        End Sub
    and .aspx page have
    Code:
    <asp:AccessDataSource ID="AccessDataSource1" runat="server"  DataFile="db/container.accdb">
                                </asp:AccessDataSource>
    i put break point on insertion line and run the query in sql view of ms access and query is working fine in access and insert record ,but its not inserting record via code ,
    There is no achievement without goals

  6. #6
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: AccessDataSource1 is not declared

    You better try this:
    Create your accessdatasource and then on the markup put all the parameters you are going to insert.
    P.e.
    Code:
     <InsertParameters>
                 <asp:Parameter Name="textname" Type="String"/>
                  <asp:Parameter Name="position" Type="Int32"/>
            </InsertParameters>
    Etc.
    If your values are fixed then insert them above.
    Else handle the accessdatasource_Inserting and use e.command.parameters.Values to set the values.
    OR
    Don't create parameters on the markup and when you go to accessdatasource_Inserting use e.command.parameters.add or addwithvalue to create your parameters.
    OR
    Don't use accessdatasource and do it with the old fashion way with the equivalent of SqlCommand, i don't recall it now, is it oledbcommand?
    Basically if you don't have a reason to use accessdatasource then don't use it.
    If you can avoid access then use sqlexpress BY ALL MEANS.
    Also you can use datasets and datatables.

    I would personally go with sqlexpress of standard sql server if you have it.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: AccessDataSource1 is not declared

    i m getting an error

    Server Error in '/gfln' Application.
    --------------------------------------------------------------------------------

    Syntax error in INSERT INTO statement.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

    Source Error:


    Line 24: cmd = New OleDbCommand(str, con)
    Line 25: 'con.Open()
    Line 26: Int(n = cmd.ExecuteNonQuery())
    Line 27: con.Close()
    Line 28:


    Source File: C:\Users\Iram\Documents\Visual Studio 2008\WebSites\gfln\Default3.aspx.vb Line: 26

    Stack Trace:


    [OleDbException (0x80040e14): Syntax error in INSERT INTO statement.]
    System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1006560
    System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +255
    System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +188
    System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
    System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +161
    System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113
    Default3.btn_submitt_Click(Object sender, EventArgs e) in C:\Users\Iram\Documents\Visual Studio 2008\WebSites\gfln\Default3.aspx.vb:26
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


    i have simple code now to insert record

    Code:
    Imports Microsoft.VisualBasic
    Imports System.Data
    Imports System.Data.OleDb
    Imports System.Data.Odbc
    
    
    Partial Class Default3
        Inherits System.Web.UI.Page
    
        Dim cmd As OleDbCommand
        Dim adapter As OleDbDataAdapter
        Dim ds As DataSet
    
        Protected Sub btn_submitt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_submitt.Click
    
            Dim n As Int32
            Dim connString As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
    
    
            Dim con As OleDbConnection = New OleDbConnection(connString)
            con.Open()
            Dim str As String
            str = "insert into users(Name,position ,[company name],Address,city,state,country,telephone,telefax,email,webaddress )values  ('" & Me.txt_name.Text & "' ,'" & Me.txt_position.Text & "','" & Me.txt_cname.Text & " ','" & Me.txt_address.Text & "' ,'" & Me.txt_city.Text & "','" & Me.txt_state.Text & "','" & Me.ddl_Country.SelectedItem.Text & "', '" & Me.txt_Telephone.Text & "','" & Me.txt_telefax.Text & "' ,'" & Me.txt_email.Text & "' ,'" & Me.txt_webaddress.Text & "') "
            cmd = New OleDbCommand(str, con)
            'con.Open()
            Int(n = cmd.ExecuteNonQuery())
            con.Close()
          
    
          
    
        End Sub
    
        Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
         
    
        End Sub
    End Class
    any thanks for every one
    There is no achievement without goals

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: AccessDataSource1 is not declared

    ok ,resolved i make everything in square brackets
    There is no achievement without goals

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width