Results 1 to 1 of 1

Thread: I can't update my database...help!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125

    I can't update my database...help!

    hi everyone! I'm having trouble with my update button...
    What my program does is it lets the user input and save new customer record/s and edits/updates the saved records (this is my problem) my main problem is that it doesn't update my database. There are no errors popping up in my system that would tell me why.

    Secondly, I made a search button so that when the customer list becomes longer, it would be easier for the user to look for a customer record. When the search button is clicked, the search form will appear and the selected record will be placed in the main form. The problem now is it copies only the customerID and not the whole record to my main form. Please please help me! I still can't program that well and will be needing so much of your help. Thanks a lot!

    Here's my code...

    Imports ExpertSearch
    Public Class Form3
    Inherits System.Windows.Forms.Form

    **I bind and created my connection,adapter and dataset using the wizard**

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
    daCust1.Fill(DsCust1)
    Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.OKOnly, "Error")
    End Try
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    Dim dr As DataRow
    Dim drcustcmd As New System.Data.OleDb.OleDbCommandBuilder(daCust1)
    daCust1.MissingSchemaAction = MissingSchemaAction.AddWithKey
    Try
    'dsCust.Clear()
    'daCust.Fill(dsCust, "Customername")
    dr = DsCust1.Tables("Customername").NewRow
    dr("CustomerID") = txtCustID.Text
    dr("Customername") = txtCustName.Text
    dr("Address") = txtCustAdd.Text
    dr("Tel") = txtCustTel.Text
    dr("Fax") = txtCustFax.Text
    dr("Attention") = txtCustAtt.Text
    DsCust1.Tables("Customername").Rows.Add(dr)
    daCust1.Update(DsCust1, "Customername")
    MsgBox("Customer record saved", MsgBoxStyle.OKOnly)
    Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.OKOnly, "Error")
    End Try
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    daCust1.Update(DsCust1, "Customername")
    End Sub

    Private Sub btnsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
    Dim mExpertSearch As New ExpertSearch()
    If mExpertSearch.Execute("Select * from CustomerName", cn1, 0) = True Then
    txtCustID.Text = mExpertSearch.FieldValue
    End If
    cn1.Close()
    End Sub

    This is the code I got from the net for the search...(I placed it in a class)

    Imports System.Windows.Forms
    Imports System.Data.OleDb
    Imports System.Data.SqlClient

    Public Class ExpertSearch
    Private mFieldValue As String
    ReadOnly Property FieldValue() As String
    Get
    Return mFieldValue
    End Get
    End Property
    Function Execute(ByVal SQL As String, ByVal DBConnection As OleDbConnection, ByVal ColumnNumberToRetrive As Integer) As Boolean
    Dim ds As New DataSet()
    Dim da As New OleDbDataAdapter(SQL, DBConnection)
    da.Fill(ds, "Table")
    Dim frmSearchForm As New Customer()
    frmSearchForm.mColNumber = ColumnNumberToRetrive
    frmSearchForm.mDS = ds
    ds = Nothing
    da = Nothing
    frmSearchForm.ShowDialog()
    If frmSearchForm.DialogResult = DialogResult.OK Then
    mFieldValue = frmSearchForm.ReturnValue
    Execute = True
    Else
    Execute = False
    End If
    End Function
    Function Execute(ByVal SQL As String, ByVal DBConnection As SqlConnection, ByVal ColumnNumberToRetrive As Integer) As Boolean
    Dim ds As New DataSet()
    Dim da As New SqlDataAdapter(SQL, DBConnection)
    da.Fill(ds, "Table")
    Dim frmSearchForm As New Customer()
    frmSearchForm.mColNumber = ColumnNumberToRetrive
    frmSearchForm.mDS = ds
    ds = Nothing
    da = Nothing
    frmSearchForm.ShowDialog()
    If frmSearchForm.DialogResult = DialogResult.OK Then
    mFieldValue = frmSearchForm.ReturnValue
    Execute = True
    Else
    Execute = False
    End If
    End Function

    End Class

    I'm hoping for your pieces of advice!
    Last edited by siomai; Jul 11th, 2004 at 07:29 PM.

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