using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;using System.Data.SqlClient;public partial class Admin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//读取关键字
try
{
string strCon = "Data Source =(local);Integrated Security = SSPI;Initial Catalog = EduDB;"; SqlConnection sqlCon = new SqlConnection(strCon);
sqlCon.Open();
//key1
SqlCommand cmdHotKey1 = new SqlCommand("SELECT HotKey FROM [TableHotkey] where ID = 1", sqlCon);
TextBoxHotKey1.Text = Convert.ToString(cmdHotKey1.ExecuteScalar());
//key2
SqlCommand cmdHotKey2 = new SqlCommand("select HotKey from TableHotKey where ID = 2", sqlCon);
TextBoxHotKey2.Text = Convert.ToString(cmdHotKey2.ExecuteScalar());
//key3
SqlCommand cmdHotKey3 = new SqlCommand("select HotKey from TableHotKey where ID = 3", sqlCon);
TextBoxHotKey3.Text = Convert.ToString(cmdHotKey3.ExecuteScalar());
//key4
SqlCommand cmdHotKey4 = new SqlCommand("select HotKey from TableHotKey where ID = 4", sqlCon);
TextBoxHotKey4.Text = Convert.ToString(cmdHotKey4.ExecuteScalar());
//key5
SqlCommand cmdHotKey5 = new SqlCommand("select HotKey from TableHotKey where ID = 5", sqlCon);
TextBoxHotKey5.Text = Convert.ToString(cmdHotKey5.ExecuteScalar()); sqlCon.Close();
}
catch
{
}
}
protected void ButtonHotKey_Click(object sender, EventArgs e)
{
try
{
string strCon = "Data Source =(local);Integrated Security = SSPI;Initial Catalog = EduDB;";
SqlConnection sqlCon = new SqlConnection(strCon);
sqlCon.Open(); string hk1 = TextBoxHotKey1.Text.Trim();
SqlCommand cmd1 = new SqlCommand("update TableHotKey set HotKey = \'" + TextBoxHotKey1.Text.Trim() + "\' where ID = 1", sqlCon);
cmd1.ExecuteNonQuery();
//这为什么不更新数据呢
sqlCon.Close();
}
catch
{
}
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;using System.Data.SqlClient;public partial class Admin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//读取关键字
try
{
string strCon = "Data Source =(local);Integrated Security = SSPI;Initial Catalog = EduDB;"; SqlConnection sqlCon = new SqlConnection(strCon);
sqlCon.Open();
//key1
SqlCommand cmdHotKey1 = new SqlCommand("SELECT HotKey FROM [TableHotkey] where ID = 1", sqlCon);
TextBoxHotKey1.Text = Convert.ToString(cmdHotKey1.ExecuteScalar());
//key2
SqlCommand cmdHotKey2 = new SqlCommand("select HotKey from TableHotKey where ID = 2", sqlCon);
TextBoxHotKey2.Text = Convert.ToString(cmdHotKey2.ExecuteScalar());
//key3
SqlCommand cmdHotKey3 = new SqlCommand("select HotKey from TableHotKey where ID = 3", sqlCon);
TextBoxHotKey3.Text = Convert.ToString(cmdHotKey3.ExecuteScalar());
//key4
SqlCommand cmdHotKey4 = new SqlCommand("select HotKey from TableHotKey where ID = 4", sqlCon);
TextBoxHotKey4.Text = Convert.ToString(cmdHotKey4.ExecuteScalar());
//key5
SqlCommand cmdHotKey5 = new SqlCommand("select HotKey from TableHotKey where ID = 5", sqlCon);
TextBoxHotKey5.Text = Convert.ToString(cmdHotKey5.ExecuteScalar()); sqlCon.Close();
}
catch
{
}
}
protected void ButtonHotKey_Click(object sender, EventArgs e)
{
try
{
string strCon = "Data Source =(local);Integrated Security = SSPI;Initial Catalog = EduDB;";
SqlConnection sqlCon = new SqlConnection(strCon);
sqlCon.Open(); string hk1 = TextBoxHotKey1.Text.Trim();
SqlCommand cmd1 = new SqlCommand("update TableHotKey set HotKey = \'" + TextBoxHotKey1.Text.Trim() + "\' where ID = 1", sqlCon);
cmd1.ExecuteNonQuery();
//这为什么不更新数据呢
sqlCon.Close();
}
catch
{
}
}
}
SqlCommand cmd1 = new SqlCommand("update TableHotKey set HotKey = \'" + TextBoxHotKey1.Text.Trim() + "\' where ID = 1", sqlCon);
这句改成
SqlCommand cmd1 = new SqlCommand("update TableHotKey set HotKey = '" + TextBoxHotKey1.Text.Trim() + "' where ID = 1", sqlCon);
试试。
toSqlCommand cmd1 = new SqlCommand(@"update TableHotKey set HotKey = '" + TextBoxHotKey1.Text.Trim() + "' where ID = 1", sqlCon);试试,不行就用参数
====================
单引号为什么要加转义符?把转义符去了看看
SqlCommand cmd1 = new SqlCommand("update TableHotKey set HotKey = '" + TextBoxHotKey1.Text.Trim() + "' where ID = 1", sqlCon);
改成这样,看HotKey能不能变成XX!!XX
每个是即开即用即关。不能共享的。
{
string strCon = "Data Source =(local);Integrated Security = SSPI;Initial Catalog = EduDB;";
SqlConnection sqlCon = new SqlConnection(strCon);
string hk1 = TextBoxHotKey1.Text.Trim();
SqlCommand cmd1 = new SqlCommand("update TableHotKey set HotKey = '" +hk1 + "' where ID = 1", sqlCon);
sqlCon.Open(); cmd1.ExecuteNonQuery();
//这为什么不更新数据呢
sqlCon.Close();
看看有没有执行?
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;using System.Data.SqlClient;public partial class Admin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//读取关键字
//try
//{
// string strCon = "Data Source =(local);Integrated Security = SSPI;Initial Catalog = EduDB;"; // SqlConnection sqlCon = new SqlConnection(strCon);
// sqlCon.Open();
// //key1
// SqlCommand cmdHotKey1 = new SqlCommand("SELECT HotKey FROM [TableHotkey] where ID = 1", sqlCon);
// TextBoxHotKey1.Text = Convert.ToString(cmdHotKey1.ExecuteScalar());
// //key2
// SqlCommand cmdHotKey2 = new SqlCommand("select HotKey from TableHotKey where ID = 2", sqlCon);
// TextBoxHotKey2.Text = Convert.ToString(cmdHotKey2.ExecuteScalar());
// //key3
// SqlCommand cmdHotKey3 = new SqlCommand("select HotKey from TableHotKey where ID = 3", sqlCon);
// TextBoxHotKey3.Text = Convert.ToString(cmdHotKey3.ExecuteScalar());
// //key4
// SqlCommand cmdHotKey4 = new SqlCommand("select HotKey from TableHotKey where ID = 4", sqlCon);
// TextBoxHotKey4.Text = Convert.ToString(cmdHotKey4.ExecuteScalar());
// //key5
// SqlCommand cmdHotKey5 = new SqlCommand("select HotKey from TableHotKey where ID = 5", sqlCon);
// TextBoxHotKey5.Text = Convert.ToString(cmdHotKey5.ExecuteScalar()); // sqlCon.Close();
//}
//catch
//{
//}
}
protected void ButtonHotKey_Click(object sender, EventArgs e)
{
try
{
string strCon = "Data Source =(local);Integrated Security = SSPI;Initial Catalog = EduDB;";
SqlConnection sqlCon = new SqlConnection(strCon);
sqlCon.Open(); string hk1 = TextBoxHotKey1.Text.Trim();
SqlCommand cmd1 = new SqlCommand("update TableHotKey set HotKey = '" + TextBoxHotKey1.Text.Trim() + "' where ID = 1", sqlCon);
cmd1.CommandType = CommandType.Text;
cmd1.ExecuteNonQuery();
//这为什么不更新数据呢
sqlCon.Close();
}
catch
{
Console.WriteLine(1111);
}
}
}