DataTable dt = new DataTable();
already add using System.Data;
anyone why i can't use DataTable in C# and i alway get this error
error CS0012: The type `System.Xml.Serialization.IXmlSerializable' is defined in an assembly that is not referenced.Consider adding a reference to assembly `System.Xml, Version=2.0.0.0, Culture=ne
utral, PublicKeyToken=b77a5c561934e089'
Solved Datatable c#
Discussion in 'Rust Development' started by PoJa, Sep 16, 2015.
-
It uses system.xml which is blacklisted and not accessible from the Oxide sandbox. Imho xml should be whitelisted, but thats another debate.
-
how can i build plugin using mysql than? cuz when we use select fuction has to use datatable
-
you'll probably want to have a php page pumping you the data as json, not sure. I haven't seen any database use other than RustIO but that one is an extension not a plugin.
-
Perhaps using the mysql extension shipped with oxide could help?
MySQL Extension | Oxide -
Code:private List<String>[] Select(String SQLCode) { List<String>[] Data; Data = new List<String>[1]; Data[0] = new List<string> { "none" }; _mySqlConnection = _mySql.OpenDb("ip", port, "db", "id", "password", this); _mySql.Query(Ext.MySql.Sql.Builder.Append(SQLCode), _mySqlConnection, list => { Console.WriteLine("Number Of List: "+list.Count); int count = list.Count; if (count != 0) { Console.WriteLine("Count is more than zero"); Dictionary<string, object> dic = list[0]; int countColumn = dic.Count; String TextDisplay = ""; Data = new List<String>[countColumn]; for (int x = 0; x < countColumn; x++) Data[x] = new List<string>(); Console.WriteLine("After set string value"); for (int x = 0; x < count; x++) { int number = 0; foreach (var pair in list[x]) { Data[number % countColumn].Add(pair.Value.ToString()); number++; } } Console.WriteLine("After Input all data"); } }); Console.WriteLine("Send Back Data"); return Data; }
i send right sqlcode but MySQLQuery don't get anything
Code this part:
_mySql.Query(Ext.MySql.Sql.Builder.Append(SQLCode), _mySqlConnection, list =>Last edited by a moderator: Sep 17, 2015 -
in a plugin you should use Puts instead of Console.WriteLine, and the mysql implementation is async, so you cannot return data from the callback method, handle the data directly in the callback/pass it to a method in your plugin.
-
I got some question why are we using Puts instead of Console.WriteLine?
How to create static _mySqlConnection?
Code:private static Ext.MySql.Connection _mySqlConnection;_mySqlConnection = _mySql.OpenDb("localhost", 3306, "rust", "root", "admin",this); <- this inside static method i can't use this but how can i change it?
-
i do it like this:
Code:// Logs a message to console public void Log(string message) { Puts("{0}: {1}", Title, message); } private void OnServerInitialized() { Log("Connecting to mySQL database..."); try { _mySqlConnection = _mySql.OpenDb("192.168.1.3", 3306, "rust", "rust", "SQLpasswordGoesHere", this); Log("OK: Connected!"); } catch(Exception ex) { Log("ERROR: There was error while connecting to mySQL database!!!"); return; } }
then later you may have something like:
Code:[HookMethod("TestMethod")] void TestMethod(){ Log("TEST SQL"); var sql = Ext.MySql.Sql.Builder.Append(@"DROP TABLE IF EXISTS example; CREATE TABLE IF NOT EXISTS example ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, data VARCHAR(100), data_other INT );"); var r = new System.Random(); for (var i = 0; i < 10; i++) { var rInt = r.Next(); sql.Append(InsertData, "test" + rInt, rInt); } _mySql.Insert(sql, _mySqlConnection); sql = Ext.MySql.Sql.Builder.Append(SelectData); _mySql.Query(sql, _mySqlConnection, list => { if (list == null) return; var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine(" id\tdata\t\tdata_other"); foreach (var entry in list) { sb.AppendFormat(" {0}\t{1}\t{2}", entry["id"], entry["data"], entry["data_other"]); sb.AppendLine(); } Puts(sb.ToString()); }); }
hope it helps -
but my point is it have to be "static" if it not static method it work fine
But Thank a lots of helping me ^^ -
- After you mark the methods as static, the compiler will emit non-virtual call sites to these members. Emitting non-virtual call sites will prevent a check at runtime for each call that ensures that the current object pointer is non-null. This can result in a measurable performance gain for performance-sensitive code. In some cases, the failure to access the current object instance represents a correctness issue.
So i believe, no it does not have to be static, but doing it static gives us some performance boost. -
you can use "private static Ext.MySql.Connection _mySqlConnection;" without any problem you just need to call OpenDb from an instance method once and assign the return value to _mySqlConnection, just like Loaded or OnServerInitialized