Firstly I presumed you are using SQLDataAdapter.
Secondly, is your connection string is correct and user & logon permission is valid, for example you may have restriction on read & write permssion.
Thirdly, you may already used your SqlDataAdater object and it is still remaining open, if trying to connect any different databases connection will be met with a problem.
This sample should work (assumed connection & logon permission is valid)
DataSet myDS=New DataSet("MyDataSet")
string cnn = data source=yourserver;user id=yourlogin;password=yourpwd;initial catalog=yourdatabase"
string sqlCmd ="SELECT * FROM TABLE1"
SqlDataAdapter myDA=new SqlDataAdapter(sqlCmd,cnn)
myDA.Fill(myDS)
This should fill your dataset, when you construct the SqlDataAdater, it should also opens the connection, if not use myDA.SelectCommand.Connectioin.Open() after constructing your adapter object.
This should auto create your table in your dataset (myDS).
Hope this help.
Cheers
Kasie
|