Bryan Posted July 10, 2004 Posted July 10, 2004 (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 July 10, 2004 by Bryan Quote
*Experts* Nerseus Posted July 11, 2004 *Experts* Posted July 11, 2004 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 Quote "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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.