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
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?
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
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.