我正在尝试将新记录添加到我的表中tblEmployee
。这是我的代码:
cb = new SqlCommandBuilder(daEmp);
DataRow dRow = dsEmp.Tables["tblEmployee"].NewRow();
dRow["EmployeeID"] = txtID.Text;
dRow["Lname"] = txtLname.Text;
dRow["Fname"] = txtFname.Text;
dRow["Mname"] = txtMname.Text;
dRow["Address"] = txtAddress.Text;
dRow["Email"] = txtEmail.Text;
dRow["Phone"] = Convert.ToInt64(txtPhone.Text);
dRow["Jobtitle"] = txtJobtitle.Text;
dRow["Salary"] = txtSalary.Text;
dRow["DeptID"] = drpDepartments.SelectedValue;
dsEmp.Tables["tblEmployee"].Rows.Add(dRow);
daEmp.Update(dsEmp, "tblEmployee");
dsEmp.Tables["tblEmployee"].AcceptChanges();
我在这一行收到此错误消息:dRow["Phone"] = txtPhone;
。它说Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.IConvertible'.Couldn't store <System.Web.UI.WebControls.TextBox> in Phone Column. Expected type is Int64.
文本框的代码:
<asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
我的数据库上列的数据类型Phone
是 int 但我将其更改为 bigint 并且仍然得到相同的错误。似乎是什么问题?
顺便说一句,我正在使用 C# ASP.NET。