A Windows application using Winforms and SQL Server in VS 2015. Project works fine at all times except from 10:00AM to 1:00PM CST.
During this time of the day, every other query like DELETE
/ UPDATE
works, but an INSERT
query does not seem to insert any data into my table. I am using ExecuteNonQuery()
to get my data inserted in my SQL table. This is a very strange problem and I do not get any error, my query works fine at other times.
Please help me if anyone has any idea! Thank you!
SqlConnection STDB = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB; AttachDbFilename=C:\VS\MainProject\MainProject\STDB.mdf;Integrated Security=True");
STDB.Open();
DialogResult result = MessageBox.Show("Do you want to save changes?", "Confirmation", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
string query10 = $"INSERT INTO [dbo].[Inbound](TrailerNo, ShipperNo,
SealNo, ReceivedBy, ReceivingShift, Carrier, Supplier, Vendor,
Contents, Location, Comments, Date, Time, Status) VALUES
('{textBox1.Text}','{textBox2.Text}','{textBox3.Text}',
'{comboBox5.Text}','{comboBox1.Text}','{comboBox6.Text}',
'{textBox4.Text}','{textBox5.Text}','{comboBox2.Text}',
'{comboBox3.Text}','{TextBox6.Text}','{dateTimePicker1.Text}',
'{dateTimePicker2.Text}','{textBox7.Text}')";
SqlDataAdapter SDA30 = new SqlDataAdapter(query10, STDB);
SDA30.SelectCommand.ExecuteNonQuery();
MessageBox.Show("Information Saved!");
clear();
}
else
{
//do nothing
}
STDB.Close();
检查您的任务计划程序和事件日志,了解在这些日子里发生了什么。
Thank you for all the help. I caught the Error! The time column in the database was set to NVARCHAR(10) and so everyday at 10:00 AM -12:59 PM there was 1 character extra, I had a catch block so did not receive any exception but on step by step info, I got to know that there was an exception "String or binary data would be truncated." I updated my Time column with NVARCHAR(50) in my data table and everything works like a charm.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.