当我尝试调试时,它给出了两个错误:
错误1'System.DateTime'不包含"值"的定义 并且没有扩展方法"值"接受类型的第一个参数 可以找到'System.DateTime'(您是Missi
enter code here
ng a 使用指令或组件 参考?)c: users home documents Visual Studio 2012 projects windowsformsapplication1 windowsformsapplication1 form1.cs 28 44 windowsformsapplication1错误2'System.DateTime'不包含"值"的定义 并且没有扩展方法"值"接受类型的第一个参数 可以找到" system.dateTime"(您是否缺少使用指令或 汇编引用?)c: users home documents Visual Studio 2012 projects windowsformsapplication1 windowsformsapplication1 form1.cs 29 40 WindowsFormsApplication1
static string connection = @"Data Source=AmayaSQLEXPRESS;Initial Catalog=myDB;Integrated Security=True";
SqlConnection con = new SqlConnection(connection);
double driverCharge;
private void btnCalculate_Click(object sender, EventArgs e)
{
DateTime startDate = dtp_rentedDate.Value;
DateTime endDate = dtp_returnedDate.Value;
int startKm = int.Parse(txtstart_Km.Text);
int endKm = int.Parse(txtend_Km.Text);
string Veh_ID = cmb_VID.SelectedValue.ToString();
double basicCharge = 0.0;
namespace WindowsFormsApplication1
{ 公共部分班级表格3:表格 { 公共形式3() { InitializeComponent(); fillcombobox(); }
static string connection = @"Data Source=DESKTOP-RFLE48TSQLEXPRESS;Initial Catalog=Ayubo_Drive;Integrated Security=True";
SqlConnection con = new SqlConnection(connection);
double driverCharge;
private void btnCalculate_Click(object sender, EventArgs e)
{
DateTime startDate = startDate.Value;
DateTime endDate = endDate.Value;
int startKm = int.Parse(txtstart_Km.Text);
int endKm = int.Parse(txtend_Km.Text);
string Veh_ID = comboBox1.SelectedValue.ToString();
double basicCharge = 0.0;
if (rbRent.Checked)
{
basicCharge = rentcalculation(Veh_ID, startDate, endDate, false);
}
else if (rbRentW_driver.Checked)
{
basicCharge = rentcalculation(Veh_ID, startDate, endDate, true);
}
txt_basic.Text = String.Format("{0:.00}", basicCharge);
}
private void FillComboBox()
{
SqlDataAdapter da = new SqlDataAdapter("Select V_ID from Vehicle_Type", con);
DataTable dt = new DataTable();
da.Fill(dt);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "V_ID";
comboBox1.ValueMember = "V_ID";
}
public double rentcalculation(string Veh_ID, DateTime startDate, DateTime endDate, bool withDriver)
{
double rent = 0.0;
try
{
SqlCommand cmd = new SqlCommand("SELECT * FROM Vehicle_Type WHERE V_ID=@001", con);
cmd.Parameters.AddWithValue("@001", Veh_ID);
con.Open();
SqlDataReader r = cmd.ExecuteReader();
if (r.Read())
{
double daycharge = double.Parse(r["V_dayRent"].ToString());
double weekcharge = double.Parse(r["v_weekRent"].ToString());
double monthlycharge = double.Parse(r["v_monthlyRent"].ToString());
driverCharge = double.Parse(r["v_driverCharge"].ToString());
TimeSpan ts = endDate.Date - startDate.Date;
int total_Days = ts.Days + 1;
int Days = total_Days;
int month = (int)Days / 30;
Days = Days % 30;
int weekCount = (int)Days / 7;
Days = Days % 7;
rent = month * monthlycharge + weekCount * weekcharge + Days * daycharge;
if (withDriver)
{
driverCharge = total_Days * driverCharge;
txt_driver.Text = driverCharge.ToString();
double totCharge = rent + driverCharge;
txt_total.Text = totCharge.ToString();
}
else
{
txt_driver.Text = "0.0";
txt_total.Text = rent.ToString();
}
}
}
catch (SqlException e)
{
e.ToString();
}
finally
{
con.Close();
}
return rent;
}
}
}
dtp_renteddate对象的数据类型是什么?看来是系统的。在这里您可以看到的,它确实不包含"价值"属性。我认为您想使用其他一些变量,该变量是可用于在GUI上输入DateTime值的视觉控制。请更好地查看您的代码,然后查看该控件的命名。然后用该字符串替换DTP_RentedDate。