bebblebrox
IS-IT--Management
ok so here's the error i'm getting (stack trace and all):
now for the code snippets: this is the handler for a button to add a new customer
here's the dataadapter & sqlcommand setup:
i can post all the code if it will help. the form contains a DataGrid which all the existing data is bound too & LoadData is a sub that binds the data.
thanks
Code:
Server Error in '/305C06' Application.
--------------------------------------------------------------------------------
String or binary data would be truncated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: String or binary data would be truncated.
Source Error:
Line 163:
Line 164: 'update database
Line 165: mda.Update(mds, "Customers")
Line 166:
Line 167: 'bind
Source File: c:\inetpub\[URL unfurl="true"]wwwroot\305C06\StepByStep6-26.aspx.vb[/URL] Line: 165
Stack Trace:
[SqlException: String or binary data would be truncated.]
System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
_305C06.StepByStep6_26.btnAdd_Click(Object sender, EventArgs e) in c:\inetpub\[URL unfurl="true"]wwwroot\305C06\StepByStep6-26.aspx.vb:165[/URL]
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
now for the code snippets: this is the handler for a button to add a new customer
Code:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim dr As DataRow = mds.Tables("Customers").NewRow
'set values
dr(0) = txtCustomerID.Text
dr(1) = txtCompanyName.Text
dr(2) = txtContactName.Text
'add row
mds.Tables("Customers").Rows.Add(dr)
'update database
mda.Update(mds, "Customers")
****previous line causes error****************
'bind
LoadData()
End Sub
here's the dataadapter & sqlcommand setup:
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'set up the sqldataadapter
Dim cmdSelect As SqlCommand = mcnn.CreateCommand
cmdSelect.CommandType = CommandType.Text
cmdSelect.CommandText = "Select CustomerID, CompanyName, ContactName from Customers"
Dim cmdInsert As SqlCommand = mcnn.CreateCommand
cmdInsert.CommandType = CommandType.Text
cmdInsert.CommandText = "Insert into Customers(CustomerID, CompanyName, " & _
"ContactName) values ('@CustomerID', '@CompanyName', " & _
"'@ContactName')"
cmdInsert.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID")
cmdInsert.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName")
cmdInsert.Parameters.Add("@ContactName", SqlDbType.NVarChar, 30, "ContactName")
cmdInsert.Parameters("@CustomerID").SourceVersion = DataRowVersion.Original
'setup data adapter and fill dataset
mda.SelectCommand = cmdSelect
mda.UpdateCommand = cmdUpdate
mda.DeleteCommand = cmdDelete
mda.InsertCommand = cmdInsert
mda.Fill(mds, "Customers")
'load datagrid
If Not IsPostBack Then
LoadData()
End If
End Sub
i can post all the code if it will help. the form contains a DataGrid which all the existing data is bound too & LoadData is a sub that binds the data.
thanks