I tried the code in this book. (see title)
(Still don't know which one? It's written by Chris Ulman, John Kauffman, Chris Hart, David Sussman.
http://www.wrox.com/WileyCDA/WroxTit...load_code.html)
Page 307 code: I typed in the code from the book.
I get this error: Exception Details: System.Data.OleDb.OleDbException: The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data.
[OleDbException (0x80040e57): The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data.]
System.Data.Common.DbDataAdapter.Update(Data Row[] dataRows, DataTableMapping tableMapping) +1644
System.Data.Common.DbDataAdapter.Update(Data Set dataSet, String srcTable) +152
ASP.update_aspx.Page_Load(Object Sender, EventArgs E) in F:\WebMatrix\Ch09\update.aspx:72
System.Web.UI.Control.OnLoad(EventArgs e) +55
System.Web.UI.Control.LoadRecursive() +27
System.Web.UI.Page.ProcessRequestMain() +731
I checked my code... My code should be fine... Is there any typed codes I can download?
Ok... I will paste my codes here as well. It's a bit long.
Thank you: Whoever replied.
<%@ Page Language="
VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
Sub Page_Load(Sender As object, E As EventArgs)
Dim connectionString As String
Dim queryString As String
Dim data As New DataSet()
Dim dbConnection As OleDbConnection
Dim dataAdapter As OleDbDataAdapter
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=F:\WebMatrix\Northwind.mdb"
queryString="SELECT EmployeeID, FirstName, LastName FROM Employees"
dbConnection = New OledbConnection(connectionString)
dataAdapter = New OledbDataAdapter(queryString, dbConnection)
dataAdapter.Fill(data, "Employees")
DataGrid1.DataSource = data.Tables("Employees")
DataGrid1.DataBind()
Dim table As DataTable
Dim newRow As DataRow
table = data.Tables("Employees")
newRow = table.NewRow()
newRow("FirstName") = "Rogerrrrrrrrrrrrrrrrr"
newRow("LastName") = "Cccccchennn"
table.Rows.Add(newRow)
newRow = table.NewRow()
newRow("FirstName") = "Sarahhhhhhhhhhhh"
newRow("LastName") = "Exxxxxxxxxx"
table.Rows.Add(newRow)
DataGrid2.DataSource=table
DataGrid2.DataBind()
Dim objRow As DataRow
objRow=table.Rows(3)
objRow("FirstName")="dkkddkd"
objRow("LastName")="deledljg"
DataGrid3.DataSource=table
DataGrid3.DataBind()
table.Rows(table.Rows.Count -2).Delete()
DataGrid4.DataSource=table
DataGrid4.DataBind()
'Generate the update commands
Dim commandBuilder As OleDbCommandBuilder
commandBuilder = New OleDbCommandBuilder(dataAdapter)
dataAdapter.UpdateCommand = commandBuilder.GetUpdateCommand()
dataAdapter.InsertCommand = commandBuilder.GetInsertCommand()
dataAdapter.DeleteCommand = commandBuilder.GetDeleteCommand()
'update data store
dataAdapter.Update(data, "Employees")
'prove the data has been updated
queryString = "SELECT EmployeeID, FirstName, LastName FROM Employees"
dbConnection.Open()
Dim command As New OleDbCommand(queryString, dbConnection)
DataGridUpdated.DataSource = _
command.ExecuteReader(CommandBehavior.CloseConnect ion)
DataGridUpdated.DataBind()
End Sub
</script>
<html>
<head>
</head>
<body>
<table width="100%">
<tbody>
<tr>
<td>
Original Data</td>
<td>
Data with new Row</td>
<td>
Data with edited Row</td>
<td>
Data with deleted Row</td>
</tr>
<tr>
<td>
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
</td>
<td>
<asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
</td>
<td>
<asp:DataGrid id="DataGrid3" runat="server"></asp:DataGrid>
</td>
<td>
<asp:DataGrid id="DataGrid4" runat="server"></asp:DataGrid>
</td>
</tr>
</tbody>
</table>
After the update:
<br />
<asp:DataGrid id="DataGridUpdated" runat="server"></asp:DataGrid>
</body>
</html>