所以我一直在研究一个新项目.我了解如何更新某个行列值:
UPDATE PlayerInfo SET GearLevel = GearLevel +1 WHERE UID = "76561198008596823" ;
Run Code Online (Sandbox Code Playgroud)
但我想在其中添加一些检查.
用言语.
如果UID ="76561198008596823"并且BankMoney = 25000000 AND GearLevel = 15 THEN GearLevel + 1 AND BankMoney - 15000000
所以我测试了:
UPDATE PlayerInfo SET GearLevel =
CASE WHEN GearLevel = 15 THEN GearLevel +1
Else
0
END ;
Run Code Online (Sandbox Code Playgroud)
但这只是在15列的所有值中加1.
如何将检查添加到CASE并减去BankMoney?或者有更简单的方法来实现这一目标吗?
所以我注意到在我的代码中我有很多重复的连接字符串,并决定将其清理一下.
我的问题是,现在我已将连接字符串放入单独的类中,我在使用时无法再打开连接 using (InfoTableConnection = new SqlConnection(infoTableConnString))
但是,如果我不使用using它工作正常.
我猜,我不太了解它是如何工作的.这是我的代码,如果有人可以解释一旦它被引入一个类和/或如何修复它究竟发生了什么.
连接类:Connection.cs
class Connection
{
public static SqlConnection InfoTableConnection = null;
public void InfoConnection()
{
string infoTableConnString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MTRInfoTables;Integrated Security=True";
using (InfoTableConnection = new SqlConnection(infoTableConnString))
InfoTableConnection.Open();
}
}
Run Code Online (Sandbox Code Playgroud)
示例代码来自: MainForm.cs
private void zGradeCombo()
{
try
{
//Connection string from class.
Connection connInfoTable = new Connection();
connInfoTable.InfoConnection();
SqlCommand cmd = new SqlCommand();
cmd.Connection = Connection.InfoTableConnection;
cmd.CommandText = "SELECT * FROM [dbo].[Item] ORDER by [Type] ASC";
SqlDataReader reader = …Run Code Online (Sandbox Code Playgroud)