如何修复错误? OrderNumber + AddOrderNumber和OrderNumber = sqlCmd1.ExecuteScalar()上出现错误.ToString();
谢谢,这是代码:
int AddOrderNumber = 1;
int OrderNumber;
TextBox1.Text = OrderNumber + AddOrderNumber;
TextBox2.Text = DateTime.Now.ToString("MM-dd-yyyy");
TextBox3.Text = (string)Session["name"];
using (SqlConnection con6 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString))
{
//Grab Customer #
using (SqlCommand sqlCmd1 = new SqlCommand { CommandText = "SELECT TOP 1 [OrderNumber] FROM [datarep].[dbo].[OrderHeader] Order By [OrderNumber] DESC", Connection = con6 })
{
con6.Open();
object result = sqlCmd1.ExecuteScalar();
if (result != null)
{
OrderNumber = sqlCmd1.ExecuteScalar().ToString();
}
else
{
}
con6.Close();
}
}
答案 0 :(得分:0)
OrderNumber = sqlCmd1.ExecuteScalar().ToString();
OrderNumber
属于int
,您尝试将string
传递给该变量。在Convert.ToInt32
上执行sqlCmd1.ExecuteScalar().ToString()
。
OrderNumber = Convert.ToInt32(sqlCmd1.ExecuteScalar().ToString());