Click here to Skip to main content
15,895,537 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I Have a Data Set Call SetItemType And It Contain Two Data Table

01) ITEM_GROUP
02) ITEM_TYPE

I Want To add Value from sql Data base To This Data Table
like followings
C#
SetItemType type = new SetItemType();
type.ITEM_GROUP = "SQL Statement";



how to do this ?
Posted
Updated 27-May-13 20:52pm
v2
Comments
Varun Sareen 28-May-13 2:30am    
Please give more clarity on this. And be specific, which datatable your are talking about?
Karthik Harve 28-May-13 2:57am    
Your question is not clear. elaborate your confusion.

you can use this way...here i mention storeprocedure "sp_test" which returns more then 1 tables then you can used this tables in below way...
C#
public DataTable GetData()
{
	SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConString"].ConnectionString);
	conn.Open();
	SqlCommand cmd = new SqlCommand("sp_test", conn);
	cmd.CommandType = CommandType.StoredProcedure;
	SqlDataAdapter MyDataAdapter = new SqlDataAdapter();
	DataSet DS = new DataSet();
	try
	{
	MyDataAdapter.SelectCommand = cmd;
	MyDataAdapter.Fill(DS);
	if (DS != null && DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0)
	{
	return DS.Tables[0];
	}
	else
	{
	return null;
	}
	}
	catch (SqlException )
	{
	throw ;
	}
	finally
	{
	if (conn.State == ConnectionState.Open)
	conn.Close();
	
	conn = null;
	}
}


may be this can help you...Thanks if you get your answer then please make as answered...
 
Share this answer
 
v2
try this...
C#
try {
	connection.Open();
	command = new SqlCommand(firstSql, connection);
	adapter.SelectCommand = command;
	adapter.Fill(ds, "First Table");

	adapter.SelectCommand.CommandText = secondSql;
	adapter.Fill(ds, "Second Table");

	adapter.Dispose();
	command.Dispose();
	connection.Close();

	//retrieve first table data
	for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) {
		Interaction.MsgBox(ds.Tables[0].Rows[i][0] + "  --  " + ds.Tables[0].Rows[i][1]);
	}
	//retrieve second table data
	for (i = 0; i <= ds.Tables[1].Rows.Count - 1; i++) {
		Interaction.MsgBox(ds.Tables[1].Rows[i][0] + "  --  " + ds.Tables[1].Rows[i][1]);
	}

} 
catch (Exception ex) 
{
	Interaction.MsgBox("");
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900