Answer the question
In order to leave comments, you need to log in
C# [SOLVED] Why isn't data being updated in SQL when requested by a program?
Hello.
There was a situation incomprehensible to me, in the written program the data in the SQLExpess database is not updated, while the same query is executed without problems in ManagementStudio SQL-Server2012.
The data should be updated on button click:
private void button4_Click(object sender, EventArgs e)
{
if (strWindowsWork != "0")
{ // Работает окно
sql_update_SectionWork_YES();
sql_up();
//label1.Text = "131313131";
}
else
{ // Не работает окно
sql_update_SectionWork_NO();
sql_up();
label1.Text = strWindowsWork;
}
}
private void sql_update_SectionWork_YES()
{
//throw new NotImplementedException();
// Подключаемся к базе данных SQL Server (начало)
string nameIP = "192.168.0.77";
string nameDB = "\\SQLEXPRESS";
string userDB = "sa";
string passBD = "193755";
SqlConnection cnn = new SqlConnection(@"Data Source=" +
nameIP + nameDB + "; User ID=" +
userDB + ";Password=" + passBD);
try
{
cnn.Open();
// Формируем запрос к базе данных - запрашиваем информацию о ЛПУ
// Запрашиваем из настроек данные о рабочем месте (начало)
string strCodeLPUunic = Properties.Settings.Default.CodeLPUunic;
string strSectionNum = Properties.Settings.Default.SectionNum;
string strSectionSubNum = Properties.Settings.Default.SectionSubNum;
string strSectionWindowsNum = Properties.Settings.Default.SectionWindowsNum;
// Запрашиваем из настроек данные о рабочем месте (конец)
// Запрос получает одно значение из БД
//string sql = "UPDATE [dbo].[InfoSectionWindows] SET [SectionWork] = '3' WHERE [CodeLPU]='42501' AND [SectionNum]='А' AND [SectionSubNum]='1' AND [SectionWindowsNum]='3'";
string sql = "UPDATE InfoSectionWindows SET SectionWork = '3' WHERE CodeLPU='42501' AND SectionNum='А' AND SectionSubNum='1' AND SectionWindowsNum='3'";
SqlCommand command3 = new SqlCommand(sql, cnn);
//// Очистка
cnn.Close();
}
catch (Exception ex)
{
label1.Text = "Нет соединения с БД ! ";
}
cnn.Close();
// Подключаемся к базе данных SQL Server (конец)
}
string sql = "UPDATE [myclinic_online_step].[dbo].[InfoSectionWindows] SET [SectionWork] = '1' WHERE [CodeLPU]='42501' AND [SectionNum]='А' AND [SectionSubNum]='1' AND [SectionWindowsNum]='2'";
Answer the question
In order to leave comments, you need to log in
After initializing the SqlCommand, you need to execute command3.ExecuteNonQuery();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question