x


parameter error in microsoft SQL connection with unity3d

Hi Unity Members,

In my project I am trying to create sqlClass to connect Microsoft sql server.

I have develop my class to some extend. For example, I can query data according to input of textbox. However, I am doning this query without using any paramater because it gives error. Part of my code-->

public class SqlClass{
string connectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=EPTT;User ID=eptt; Password=123; Trusted_Connection=False; ";
SqlConnection cnn = new SqlConnection();
public SqlClass()
{
    cnn.ConnectionString = connectionString;
}

public DataTable Fill(string sql, params SqlParameter[] prms)
{//with parameter
    SqlCommand cmd = new SqlCommand(sql, cnn);
    if (prms != null)
    {
        cmd.Parameters.AddRange(prms);

    }
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    return dt;
}

public DataTable Fill(string sql)
{//without parameter
    SqlCommand cmd= new SqlCommand(sql,cnn);
    SqlDataAdapter da= new SqlDataAdapter(cmd);
    DataTable dt= new DataTable();
    int dene=da.Fill(dt);
    return dt;
}
}

as you can see two types of my query functions. The firs one contain cmd.Parameters.AddRange(prms); line. This line AddRange is unknown in unity (In .Net web apllication this class run without any problem). Therefore, I use Add instead of AddRange but this time it gives error "InvalidCastException:The parameter was not an SqlParameter"

could you help me, I will be glad to read your ideas. Tnx,

more ▼

asked Feb 03 '12 at 01:24 AM

uboncukcu gravatar image

uboncukcu
6 3 6 7

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x839
x232
x88
x62
x29

asked: Feb 03 '12 at 01:24 AM

Seen: 528 times

Last Updated: Feb 03 '12 at 01:24 AM