これを書き換えて、文字列値の代わりにパラメータを使用する方法を教えてください。私は "SqlCommand"のためにそれを行う方法を知っていますが、私はここでそれを動作させることはできません。ここでSQLパラメータを使用した書き換え
protected void searchFill()
{
orderByString = orderByList.SelectedItem.Value;
fieldString = searchTextBox.Text;
string sqlStatement = "SELECT * FROM SecureOrders WHERE fName LIKE @fieldString OR lName LIKE @fieldString OR addr LIKE @fieldString OR addr2 LIKE @fieldString OR city LIKE @fieldString OR state LIKE @fieldString OR zip LIKE @fieldString OR zip LIKE @fieldString OR country LIKE @fieldString OR email LIKE @fieldString OR phone LIKE @fieldString OR ccType LIKE @fieldString OR ccNum LIKE @fieldString OR ccExp LIKE @fieldString OR cwaSource LIKE @fieldString OR cwaJoined LIKE @fieldString OR length LIKE @fieldString OR delivery LIKE @fieldString OR price LIKE @fieldString OR url LIKE @fieldString ORDER BY @orderByString";
using (SqlConnection connection = new SqlConnection(connectionString.ToString()))
{
connection.Open();
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlStatement, connection);
dataAdapter.SelectCommand.Parameters.AddWithValue("@fieldString", fieldString);
dataAdapter.SelectCommand.Parameters.AddWithValue("@orderByString", orderByString);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "SecureOrders");
DataView source = new DataView(dataSet.Tables[0]);
DefaultGrid.DataSource = source;
DefaultGrid.DataBind();
connection.Close();
}
}
私はパラメータを使用しています私の他の方法はSqlDataAdapter
の
protected void updateCheck(bool checkValue, int identity)
{
string checkStatement = "UPDATE dbo.SecureOrders SET processed = @Processed WHERE IdentityColumn LIKE @identity";
using (SqlConnection connection = new SqlConnection(connectionString.ToString()))
using (SqlCommand _check = new SqlCommand(checkStatement, connection))
{
_check.Parameters.Add("@Processed", SqlDbType.Bit).Value = checkValue;
_check.Parameters.Add("@identity", SqlDbType.Int).Value = identity;
connection.Open();
_check.ExecuteNonQuery();
connection.Close();
}
}
私はこれをvb.netとしますか?使用している言語を質問のタグに追加する必要があります。 –
@Marc B:C# –
のように見える@Neil、それは非常にエラーの可能性がありますVB:D – musefan