Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I am trying to insert a new record into a database table. When I click the add listing button it thinks for a moment and then it's done. I don't get any errors. When I check the database itself, nothing has been added. Anybody able to offer some help please? This is ASP.net and you can view the page at http://209.30.71.112/AxisFellowship/directory/index.aspx

 

Dim MySqlConn As SqlConnection
Dim MySqlAdapter As SqlDataAdapter

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim MyDS As New DataSet()
       Dim DirectoryTable As DataTable
       Dim DirectoryRow As DataRow
       Dim ConnStr As String
       Dim SQL As String
       ConnStr = "server=(local)\SQL;database=axis;UID=sa;PWD=sa;Trusted_Connection=yes"
       SQL = "SELECT * FROM Directory"
       MySqlConn = New SqlConnection(ConnStr)
       MySqlAdapter = New SqlDataAdapter(SQL, ConnStr)


       MySqlAdapter.Fill(MyDS)

       DirectoryTable = MyDS.Tables(0)
       DirectoryRow = DirectoryTable.NewRow()
       DirectoryRow("FirstName") = txtFirstName.Text
       DirectoryRow("LastName") = txtLastName.Text
       DirectoryRow("Email") = txtEmailAddress.Text
       DirectoryRow("Password") = txtPassword.Text
       DirectoryRow("Address") = txtAddress.Text
       DirectoryRow("City") = txtCity.Text
       DirectoryRow("State") = txtState.Text
       DirectoryRow("ZipCode") = txtZipCode.Text
       DirectoryRow("PrimaryPhone") = txtPrimaryPhone.Text
       DirectoryRow("SecondaryPhone") = txtSecondaryPhone.Text
       DirectoryRow("AOLIM") = txtAOL.Text
       DirectoryRow("ICQ") = txtICQ.Text
       DirectoryRow("MSN") = txtMSN.Text
       DirectoryRow("Yahoo") = txtYahooID.Text
       DirectoryRow("Birthday") = txtBirthday.Text

       MySqlAdapter.InsertCommand = CreateDataAdapterInsertCommand()
       MySqlAdapter.Update(DirectoryTable)

       MyDS.Reset()



   End Sub
   Private Function CreateDataAdapterInsertCommand() As SqlCommand
       Dim strSQL As String
       strSQL = "INSERT INTO Directory " & _
                "    (FirstName, LastName, Email, Password, Address, City, State, ZipCode, " & _
                "    PrimaryPhone, SecondaryPhone, AOLIM, ICQ, MSN, Yahoo, Birthday) " & _
                "    Values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
       Dim cmd As New SqlCommand(strSQL, MySqlConn)
       Return cmd

   End Function

Edited by Bryan
  • *Experts*
Posted

You need to add the row back to the datatable. NewRow just gives a new row, but doesn't add it to the Datatable:

       DirectoryRow("Birthday") = txtBirthday.Text 

       [b]DirectoryTable.Rows.Add(DirectoryRow)[/b]

       MySqlAdapter.InsertCommand = CreateDataAdapterInsertCommand() 

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...