1
Reply

problem using a function for several tablenames

teoman

teoman

Oct 30 2005 7:38 PM
2k
ok.. i have a function and it looks like this..

public static void test(ListBox lst,string tablename)
{

string myConn = "Server
=(local);Integrated security=SSPI;database=halkdanis";

string str = "SELECT * FROM '"+tablename+"'"; SqlDataAdapter dataAdapter = new SqlDataAdapter(str,myConn);
DataSet dt = new DataSet();
DataAdapter.Fill(dt,tablename); // here it says error
DataTable dtb = dt.Tables[0];
foreach(DataRow dtr in dtb.Rows)
{
lst.Items.Add(dtr["username"]);
}

}

as u can see, i want to get data from mssql
, and put the usernames in a listbox and i want to use this function several times depends on tablenames but it gives error at

DataAdapter.Fill(dt,tablename) ;

i guess its coz of `"` char or dunno what is it..

any help would be great..

thx.
good coding..

 


Answers (1)