I'm trying to get an list of items from some table of SQL Server. I'm doing it with Visual Studio 2010.
That's my code:
static string filter = "25";
DataSet Datos = new DataSet();
SqlConnection MyConnection = default(SqlConnection);
SqlDataAdapter MyDataAdapter = default(SqlDataAdapter);
MyConnection = new SqlConnection("Initial Catalog=MyDataBase;Data Source=MyServer;Integrated Security=false;User ID=SQLUser;Password=SQLPass;");
MyDataAdapter = new SqlDataAdapter("SELECT Comment FROM MyTable WHERE [No_] = "+filter+" , MyConnection);
MyDataAdapter.SelectCommand.CommandType = CommandType.Text;
MyDataAdapter.Fill(Datos);
MyDataAdapter.Dispose();
MyConnection.Close();
I'm getting this error:
Argument 1: cannot convert from 'string' to 'System.Data.SqlClient.SqlCommand'
On this line:
MyDataAdapter = new SqlDataAdapter("SELECT Comment FROM MyTable WHERE [No_] = "+filter+" , MyConnection);
So, how can I put the string into my SqlConnection
?
Thanks in advance.