Я впервые работаю со средством выбора даты в C#.
Ниже приведен мой пользовательский элемент управления данными для вставки. Он добавляет все данные, присутствующие во всех текстовых полях, в DB.Neglect, но дата заказа и дата вызова не работают.
Тип данных всех текущих дат в БД - «дата».
Когда я запускаю программу, вставляю и нажимаю txtbox текущей даты автоматически заполняется текущей датой [как запрограммировано], но вставляется в таком формате «дд / мм / гггг».
Но раньше, когда я использовал для ввода даты в текстовое поле вручную, формат быть 'гггг-мм-дд'. Ранее удалось вставить дату в БД, но теперь это не так.
Я думаю, это из-за формата даты, и я что-то упустил в своем коде:
private bool insertdata()
{
//I've included the value of current date text box in string format which I think may be causing problem
string custname = txtcustname.Text, custcat = cmbcustcat.Text, date = txtdate.Text, phoneno = txtphoneno.Text, dresstype = cmbtype.Text, pattern = cmbpattern.Text, height = txtheight.Text, waist = txtwaist.Text, padar = txtpadar.Text, advance = txtadvance.Text;
if (custname != null && custcat != null && date != null && phoneno != null && dresstype != null && pattern != null && height != null && waist != null && padar != null)
{
cmd = new SqlCommand("INSERT INTO ordertbl(cust_name,cust_cat,date,phoneno,dress_type,pattern,height,waist,padar,adv) VALUES('" + custname + "','" + custcat + "','" + date + "','" + phoneno + "','" + dresstype + "','" + pattern + "','" + height + "','" + waist + "','" + padar + "','" + advance + "')", con);
cmd.ExecuteNonQuery();
return true;
}
else
{
return false;
}
//this method is called in the add data button
}
private void calenderdate(TextBox txtbox)
{
//autofills textbox with current date...The drop down arrow beside the txtbox is the DTP and it is initially not visible.
if (calcurrentdate.Visible == false)
{
calcurrentdate.Visible = true;
txtbox.Text = calcurrentdate.Value.ToShortDateString();
}
}
private void txtdate_Click(object sender, EventArgs e)
{
//when the text box of currentdate is clicked it is auto filled with today's date
calenderdate(txtdate);
}