![]() |
Click here to advertise with us
|
|
|||||||
| Database General Discussion General discussion on database related topics |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
hi
i m finding difficulty with a minor proj i have been given i have just started to learn .net so if the questions are silly the do help me out i have to create a web form that has fields first name, last name, age, number of an employee and then push these in a database i am using a ms access database with fields number(primary key) , full name, age here is what i have coded Imports System.Data Imports System.Data.OleDb Partial Public Class _Default Inherits System.Web.UI.Page Dim firstname As String Dim lastname As String Dim age As Integer Dim empnum As Integer Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox1.TextChanged firstname = TextBox1.Text End Sub Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox2.TextChanged lastname = TextBox2.Text End Sub Protected Sub TextBox3_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox3.TextChanged age = Val(TextBox3.Text) End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Dim con As New OleDb.OleDbConnection con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\mukul\My Documents\emp.mdb" con.Open() MsgBox("A Connection to the Database is now open") Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String sql = "Select * from employee" da = New OleDb.OleDbDataAdapter(Sql, con) da.Fill(ds, "employee") Dim i As Integer i = ds.Tables("employee").Rows.Count Dim dsNewRow As DataRow dsNewRow = ds.Tables("employee").NewRow() dsNewRow.Item(0) = empnum dsNewRow.Item(1) = firstname & " " & lastname dsNewRow.Item(2) = age ds.Tables("employee").Rows.Add(dsNewRow) da.Update(ds, "employee") End Sub Protected Sub TextBox4_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox4.TextChanged empnum = Val(TextBox4.Text) End Sub End Class this prog is showing an error in the update statement the error is "Update requires a valid InsertCommand when passed DataRow collection with new rows." i dont knw what it is.. n i have no idea to how to correct it can ne one help me out. and provide me with corrections or corrected code... i dnt have time.. i have to submit it tomoro |
|
||||
|
Data can't be saved to a database without some SQL code to control how it's done. If you add new rows to a DataTable you can't save those new rows without a SQL INSERT statement. You need to provide that INSERT statement to your OleDbDataAdapter, in the form of its InsertCommand property, either by manually creating an OleDbCommand or by using an OleDbCommandBuilder to generate it. You should look up the OleDbDataAdapter.InsertCommand property and/or the OleDbCommandBuilder class in the MSDN Library documentation.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms MSDN: Data Walkthroughs | "How Do I?" Videos My Blog: Custom Events | Dynamic GDI+ Drawing |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|