mysql-parameter

C# MySqlParameter problem

﹥>﹥吖頭↗ 提交于 2020-01-19 06:10:25
问题 (int) faultsGroup is 0 or 1 but i always get this error: Column 'FaultGroup' cannot be null Does anyone tell me why? Syntax looks ok. MySqlCommand cmdAdd = new MySqlCommand("INSERT INTO Faults (" + " FaultGroup, Text, Date, IP" + ") VALUES (" + " @FaultGroup, @Text, @Date, @IP" + ")", conn); MySqlParameter paramFaultGroup = new MySqlParameter("@FaultGroup", MySqlDbType.Int32); FaultsGroup faultsGroup = (FaultsGroup) Enum.Parse(typeof (FaultsGroup), myFault.FaultGroup); paramFaultGroup.Value =

C# MySqlParameter problem

最后都变了- 提交于 2020-01-19 06:07:24
问题 (int) faultsGroup is 0 or 1 but i always get this error: Column 'FaultGroup' cannot be null Does anyone tell me why? Syntax looks ok. MySqlCommand cmdAdd = new MySqlCommand("INSERT INTO Faults (" + " FaultGroup, Text, Date, IP" + ") VALUES (" + " @FaultGroup, @Text, @Date, @IP" + ")", conn); MySqlParameter paramFaultGroup = new MySqlParameter("@FaultGroup", MySqlDbType.Int32); FaultsGroup faultsGroup = (FaultsGroup) Enum.Parse(typeof (FaultsGroup), myFault.FaultGroup); paramFaultGroup.Value =

Add List<int> to a mysql parameter

安稳与你 提交于 2019-12-29 03:36:20
问题 I have this question about the MySqlParameter from the .NET connector. I have this query: SELECT * FROM table WHERE id IN (@parameter) And the MySqlParameter is: intArray = new List<int>(){1,2,3,4}; ...connection.Command.Parameters.AddWithValue("parameter", intArray); This is possible? Is possible to pass an array of int to a single MySqlParameter? The other solution will be convert the array of int to a string such like "1,2,3,4", but this, when i pass it to the MySqlParameter and this is

C# and MySQL .NET Connector - Any way of preventing SQL Injection attacks in a generic class?

时间秒杀一切 提交于 2019-12-28 05:46:27
问题 My idea is to create some generic classes for Insert/Update/Select via a C# (3.5) Winforms app talking with a MySQL database via MySQL .NET Connector 6.2.2. For example: public void Insert(string strSQL) { if (this.OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(strSQL, connection); cmd.ExecuteNonQuery(); this.CloseConnection(); } } Then from anywhere in the program I can run a query with/without user input by just passing a SQL query string. Reading around on SO is starting

MySqlParameter as TableName

怎甘沉沦 提交于 2019-12-17 20:56:13
问题 I want to use MySqlParameter to pass tableName into query (to prevent slq injections) MySqlCommand cmd = new MySqlCommand("select * from @table"), cn) cmd.Parameters.AddWithValue("@table",TableName); But this is not working. How can I pass tableName as parameter P.S. I tried to change @ to ? - not working 回答1: You cannot pass table name as parameter. You have to use dynamic SQL to do this, so you have to string concentration to do it, for example MySqlCommand cmd = new MySqlCommand(String

MySQL query parameters in a Pentaho CE dashboard

早过忘川 提交于 2019-12-11 06:29:09
问题 First, I'm on Pentaho CE 8.0. And I'm not an expert on Pentaho . The question seems simple but I cannot get it working. I'm trying for a dashboard to use a simple parameter for a WHERE condition in a MySQL query . The Bootstrap layout has 3 columns, one for each component (filter, text, table). Simple parameter: - Name: salesrep_selection - Property value: mike Filter component (to select the sales rep): - Name: salesrep_selection_filter - Parameter: salesrep_selection - Values Array: [["mike

Add List<int> to a mysql parameter

别说谁变了你拦得住时间么 提交于 2019-11-28 19:28:55
I have this question about the MySqlParameter from the .NET connector. I have this query: SELECT * FROM table WHERE id IN (@parameter) And the MySqlParameter is: intArray = new List<int>(){1,2,3,4}; ...connection.Command.Parameters.AddWithValue("parameter", intArray); This is possible? Is possible to pass an array of int to a single MySqlParameter? The other solution will be convert the array of int to a string such like "1,2,3,4", but this, when i pass it to the MySqlParameter and this is recognized as a string, it puts in the sql query like "1\,2\,3\,4" and this do not return the expected

MySqlParameter as TableName

感情迁移 提交于 2019-11-28 14:12:15
I want to use MySqlParameter to pass tableName into query (to prevent slq injections) MySqlCommand cmd = new MySqlCommand("select * from @table"), cn) cmd.Parameters.AddWithValue("@table",TableName); But this is not working. How can I pass tableName as parameter P.S. I tried to change @ to ? - not working Vimvq1987 You cannot pass table name as parameter. You have to use dynamic SQL to do this, so you have to string concentration to do it, for example MySqlCommand cmd = new MySqlCommand(String.Format("select * from {0}",tableName), cn) But because users input the tableName, so SQL injection is

C# MySqlParameter problem

那年仲夏 提交于 2019-11-28 01:18:34
(int) faultsGroup is 0 or 1 but i always get this error: Column 'FaultGroup' cannot be null Does anyone tell me why? Syntax looks ok. MySqlCommand cmdAdd = new MySqlCommand("INSERT INTO Faults (" + " FaultGroup, Text, Date, IP" + ") VALUES (" + " @FaultGroup, @Text, @Date, @IP" + ")", conn); MySqlParameter paramFaultGroup = new MySqlParameter("@FaultGroup", MySqlDbType.Int32); FaultsGroup faultsGroup = (FaultsGroup) Enum.Parse(typeof (FaultsGroup), myFault.FaultGroup); paramFaultGroup.Value = (int) faultsGroup; cmdAdd.Parameters.Add(paramFaultGroup); cmdAdd.ExecuteNonQuery(); I haven't used

C# and MySQL .NET Connector - Any way of preventing SQL Injection attacks in a generic class?

吃可爱长大的小学妹 提交于 2019-11-27 20:51:09
My idea is to create some generic classes for Insert/Update/Select via a C# (3.5) Winforms app talking with a MySQL database via MySQL .NET Connector 6.2.2. For example: public void Insert(string strSQL) { if (this.OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(strSQL, connection); cmd.ExecuteNonQuery(); this.CloseConnection(); } } Then from anywhere in the program I can run a query with/without user input by just passing a SQL query string. Reading around on SO is starting to give me the indication that this may lead to SQL injection attacks (for any user-input values). Is