Hi,
I do agree with "DamithSL" and there is one more way to do this as well.
you can use :
SELECT *
FROM server1table
INNER JOIN server2.database.dbo.server2table ON .....
For better understanding follow
here...
Your updated method here:
using System.Data.SqlClient;
string queryString = "Select productID from Table1 where custid="+ textbox1.text;
List TempproductID = new List() ;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
if (!reader.IsDBNull(0))
{
Tempproductid.add( reader[0].ToString());
}
}
reader.Close();
tempproductid.toarray();
}
method 2:
String stringprovider = "@database connection string ";
string strProductIds = " (";
for ( int I = 0; I < tempproductid.count; I++)
{
strProductIds += Convert.ToString(tempproductid[I]) + ",";
}
strProductIds = strProductIds.Remove(strProductIds.Length - 1);
strProductIds = strProductIds + ")"
Sqlconnection con2 = new sqlconnection(stringprovider);
Con2.open();
Cmd2.connection=con2;
Cmd2.commandType = new commandType.text;
Cmd2.commandText = "select * from Table2 where Productid in @productid";
Cmd2.parameters.addwithvalue("@productid",strProductIds);
Dataset Ds = new dataset();
sqldataadaptaer da1 = new sqldataadapter(cmd2);
Datatable Table2 = new Data table();
Da1.fill(table2);
Datagridview2.source = table2;
}
Thanks,
Sisir Patro