mukulmukul
Member
- Joined
- Jun 21, 2009
- Messages
- 10
- Programming Experience
- Beginner
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
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