0
Santhosh's translation looks OK to me except for this line:
Dim A(i - 1, data.FieldCount - 1)
where he has:
[,] A = new[];
I think that needs to be:
object[,] A = new object[i, data.FieldCount];
Notice also that you need to be using C# 4.0 (VS 2012) or later for the GetArray method to support the use of the optional parameter, LocalServer.
0
Hi Hussain,
You can convert it by using some online tools as below
http://www.developerfusion.com/tools/convert/vb-to-csharp/
Thanks
0
using System;
using System.Data;
using System.Data.SqlClient;
public class clsDML
{
public SqlConnection conn;
public object DML(string Query)
{
try {
string connectionstring = null;
connectionstring = CreateConnection();
conn = new SqlConnection(connectionstring);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = Query;
cmd.ExecuteNonQuery();
conn.Close();
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
}
}
public object GetArray(string Query, string LocalServer = "")
{
try {
string connectionstring = null;
connectionstring = CreateConnection();
conn = new SqlConnection(connectionstring);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = Query;
SqlDataReader data = cmd.ExecuteReader();
//reader = command.ExecuteReader();
Int32 i = default(Int32);
Int32 j = default(Int32);
Int32 x = default(Int32);
while ((data.Read())) {
i = i + 1;
}
Int32 count = default(Int32);
[,] A = new[];
count = data.FieldCount;
data.Close();
SqlDataReader data1 = cmd.ExecuteReader();
j = 0;
while ((data1.Read())) {
for (x = 0; x <= count - 1; x++) {
A(j, x) = data1.GetValue(x).ToString();
}
j = j + 1;
}
data1.Close();
return A;
} catch (Exception ex) {
}
}
public string CreateConnection()
{
string source = null;
source = "data source=(local);database=mdin;user id=sa; pwd=;Persist Security Info=False";
return source;
}
}
//
