Go4Expert

Go4Expert (http://www.go4expert.com/)
-   ASP.NET (http://www.go4expert.com/forums/asp-net/)
-   -   updating database from the website using asp.net (http://www.go4expert.com/forums/updating-database-website-using-aspnet-t19800/)

chizmo 18Oct2009 04:05

updating database from the website using asp.net
 
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

nimesh 18Oct2009 13:33

Re: updating database from the website using asp.net
 
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?

chizmo 27Oct2009 09:24

Re: updating database from the website using asp.net
 
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


nimesh 27Oct2009 10:10

Re: updating database from the website using asp.net
 
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: vb

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.

chizmo 31Oct2009 02:29

Re: updating database from the website using asp.net
 
Thank you very much. I think i had a litle problem with my database. now its working.

nimesh 31Oct2009 19:54

Re: updating database from the website using asp.net
 
what kind of problem?


All times are GMT +5.5. The time now is 05:01.