本文介绍了必须声明标量变量。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想从datagrid和datatable中删除一行。所以我编写了以下过程来完成。 现在我的错误是没有声明Scalar变量。我真的不知道如何解决这个问题 我尝试过的事情: int selectedIndex = datagriduser.SelectedIndex; DataRowView rowview = datagriduser.SelectedItem as DataRowView; // string cltyp = rowview [ClientTyp]。ToString(); var cltyp = ; var macadress = ; var userkenn = ; // OleDbCommand olecmd = new OleDbCommand(从AktiveUser删除WHERE User_Kennzeichen ='nh',conn) ; string query = 从AktiveUser删除WHERE ClientTyp = @cltyp AND MAC_Adresse = @macadress AND User_Kennzeichen = @userkenn; OleDbCommand olecmd = new OleDbCommand(query,conn); // olecmd.ExecuteNonQuery(); // OleDbCommand olecmd = new OleDbCommand(从AktiveUser删除WHERE User_Kennzeichen ='nh',conn); olecmd .Parameters.AddWithValue(@ cltyp,rowview [ ClientTyp]。ToString()); olecmd.Parameters.AddWithValue(@macadress,rowview [ Arbeitsplatz]。ToString( )); olecmd.Parameters.AddWithValue(@userkenn,rowview [ Anmeldung]。ToString( )); if (selectedIndex!= -1) { var deletedrow = dbtable.Rows [selectedIndex]; deletedrow.Delete(); oleda.DeleteCommand = olecmd; oleda.Update(dbtable); } else { System.Windows.MessageBox.Show( 请选择要删除的行); } 解决方案 尝试对您的问题进行这些更改 string query = 从AktiveUser删除WHERE ClientTyp =?AND MAC_Adresse =?AND User_Kennzeichen =?; OleDbCommand olecmd = new OleDbCommand(query,conn); olecmd.Parameters.AddWithValue( @ cltyp,rowview [ ClientTyp]。ToString()); olecmd.Parameters.AddWithValue( @ macadress,rowview [ Arbeitsplatz]。ToString()); olecmd.Parameters.AddWithValue( @ userkenn,rowview [ Anmeldung]。ToString()); I want to delete a row from datagrid and datatable. So I wrote the following process to be done.Now my error is that the Scalar variable is not declared. I literally don't know how to fix thisWhat I have tried:int selectedIndex = datagriduser.SelectedIndex; DataRowView rowview = datagriduser.SelectedItem as DataRowView; // string cltyp = rowview["ClientTyp"].ToString(); var cltyp = ""; var macadress = ""; var userkenn = ""; // OleDbCommand olecmd = new OleDbCommand("DELETE From AktiveUser WHERE User_Kennzeichen = 'nh'", conn); string query = "DELETE From AktiveUser WHERE ClientTyp= @cltyp AND MAC_Adresse = @macadress AND User_Kennzeichen = @userkenn"; OleDbCommand olecmd = new OleDbCommand(query, conn); // olecmd.ExecuteNonQuery(); // OleDbCommand olecmd = new OleDbCommand("DELETE From AktiveUser WHERE User_Kennzeichen = 'nh'", conn); olecmd.Parameters.AddWithValue(@cltyp, rowview["ClientTyp"].ToString()); olecmd.Parameters.AddWithValue(@macadress, rowview["Arbeitsplatz"].ToString()); olecmd.Parameters.AddWithValue(@userkenn, rowview["Anmeldung"].ToString()); if (selectedIndex != -1) { var deletedrow = dbtable.Rows[selectedIndex]; deletedrow.Delete(); oleda.DeleteCommand = olecmd; oleda.Update(dbtable); } else { System.Windows.MessageBox.Show("Please Select a row to Delete"); } 解决方案Try these changes to your problemstring query = "DELETE From AktiveUser WHERE ClientTyp= ? AND MAC_Adresse = ? AND User_Kennzeichen = ?";OleDbCommand olecmd = new OleDbCommand(query, conn);olecmd.Parameters.AddWithValue("@cltyp", rowview["ClientTyp"].ToString());olecmd.Parameters.AddWithValue("@macadress", rowview["Arbeitsplatz"].ToString());olecmd.Parameters.AddWithValue("@userkenn", rowview["Anmeldung"].ToString()); 这篇关于必须声明标量变量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 19:38