1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

updating database from the website using asp.net

Discussion in 'ASP.NET' started by chizmo, Oct 17, 2009.

  1. chizmo

    chizmo New Member

    Joined:
    Jun 19, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    bank clerk
    Location:
    malawi
    Hi,
    am developing a website that is supposed to connect to a database. am using VB 2005 Asp.net and am new to this. the problem am having is to update the database using the values from the textbox. help me please with this problem. Thanks
     
  2. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    Can you post the code that you've written to update the database, so that someone can check and correct it?

    Also if you are getting any error?
     
  3. chizmo

    chizmo New Member

    Joined:
    Jun 19, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    bank clerk
    Location:
    malawi
    here is the Code

    Code:
     Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
            'Set up connection string
            Dim cnString As String
    
            cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=D:\Documents and Settings\caleb\My Documents\Visual Studio 2005\WebSites\FromNet\App_Data\Aid_database.mdb"
            'Dim intId As Integer
            ' intId = Me.txtsearch.Text
            Dim sqlQRY As String = "SELECT * FROM Contactable_Contributors  WHERE Company = '" & txtsearch.Text & "'"
    
            'Create connection
            Dim conn As OleDbConnection = New OleDbConnection(cnString)
    
            Try
                ' Open connection
                conn.Open()
    
                'create data adapter
                Dim da As OleDbDataAdapter = New OleDbDataAdapter(sqlQRY, conn)
    
                'create command builder
                Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)
    
                'create dataset
                Dim ds As Data.DataSet = New Data.DataSet
    
                'fill dataset
                da.Fill(ds, "Contactable_Contributors")
    
                'get data table
                Dim dt As Data.DataTable = ds.Tables("Contactable_Contributors")
    
                With dt
    
    
                    .Rows(0)("Id") = Convert.ToString(txtId.Text)
                    .Rows(0)("Company") = Convert.ToString(txtCompany.Text)
                    .Rows(0)("Last_name") = Convert.ToString(txtsurname.Text)
                    .Rows(0)("First_name") = Convert.ToString(txtfirstname.Text)
                    .Rows(0)("E-mail") = Convert.ToString(txtEmail.Text)
                    .Rows(0)("Job_Title") = Convert.ToString(txtJob.Text)
                    .Rows(0)("Business_Phone") = Convert.ToString(txtB_Phone.Text)
                    .Rows(0)("Fax_Number") = Convert.ToString(txtFax.Text)
                    .Rows(0)("Address") = Convert.ToString(txtAddress.Text)
                    .Rows(0)("City") = Convert.ToString(txtCity.Text)
                    .Rows(0)("State") = Convert.ToString(TxtState.Text)
                    .Rows(0)("Country") = Convert.ToString(txtCountry.Text)
                   
    
                End With
    
                da.Update(ds, "Contactable_Contributors")
    
                MsgBox("Record successfully saved...", MsgBoxStyle.Information)
            Catch ex As OleDbException
                MsgBox("Error: " & ex.ToString & vbCrLf)
            Finally
                ' Close connection
                conn.Close()
            End Try
     
    Last edited by a moderator: Oct 27, 2009
  4. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    What error do you get when running the program?

    I don't know if this could be the problem or not, little correction suggested as below.

    Code:
    cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & Server.MapPath("./App_Data/Aid_database.mdb") & ";User Id=admin;Password=;"
    apart from this I don't see anything that could cause the problem.
     
  5. chizmo

    chizmo New Member

    Joined:
    Jun 19, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    bank clerk
    Location:
    malawi
    Thank you very much. I think i had a litle problem with my database. now its working.
     
  6. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    what kind of problem?
     

Share This Page