1
我需要用它來update
的note column in sql table
C#SQL更新查詢
using (SqlConnection conn = new SqlConnection())
{
SqlConnection connorder = new SqlConnection("Data Source=P4\\WORK;Initial Catalog=Agenda_X1;Persist Security Info=True;User ID=sa;Password=xxx");
connorder.Open();
string ordernrsql = lbOrderNr.Text;
string newstate = lbNewState.Text;
SqlCommand commandorder = new SqlCommand("UPDATE [Agenda_X1].[dbo].[Order] SET Note = @lbNewState WHERE OrderNr= @ordernumber", connorder);
commandorder.Parameters.Add("@ordernumber", SqlDbType.NVarChar).Value = ordernrsql;
commandorder.Parameters.Add("@lbNewState", SqlDbType.NVarChar).Value = newstate;
connorder.Close();
}
在VS FR - SQL Commnad展臺看起來像這樣
`DECLARE @ordernumber NVarChar;
SET @ordernumber = 'OPT1710420';
DECLARE @lbNewState NVarChar;
SET @lbNewState = 'Order changed 2017.06.02';
UPDATE [SAgenda_X1].[dbo].[Objednavky_ObjednavkaPrijata] SET Note= @lbNewState WHERE OrderNr = @ordernumber
但是在SQL這didn`t工作,並應是這樣的:
`DECLARE @ordernumber NVarChar (max);
SET @ordernumber = 'OPT1710420';
DECLARE @lbNewState NVarChar (max);
SET @lbNewState = 'Order changed 2017.06.02';
UPDATE [SAgenda_X1].[dbo].[Objednavky_ObjednavkaPrijata] SET Note= @lbNewState WHERE OrderNr = @ordernumber
也想問你我該怎麼做最後的sql查詢無線將已經與NVarChar (max)
??
我已經嘗試
commandorder.Parameters.Add("@ordernumber", SqlDbType.NVarChar, -1).Value = ordernrsql;
commandorder.Parameters.Add("@lbNewState", SqlDbType.NVarChar, -1).Value = newstate;
但還是SQL,並且不需要改變。
你'SAgenda_X1'和其他你有'Agenda_X1'作爲數據庫名稱。你是否只嘗試過模式和表名,比如'UPDATE [dbo]。[Order] SET Note' ... – Nino