How to convert int to datatable ,Is it possible?

Posted by Manikattamuri under ASP.NET on 8/22/2012 | Points: 10 | Views : 2257 | Status : [Member] | Replies : 4
Hello Friends,
can we convert int to datatable .
I am getting the result in int, but i am not able to assign that result to my datatable. How to achieve this?

public DataTable LoadAll()
{
DataTable table = new DataTable();
string sql = "SELECT name FROM master..sysdatabases";
int result = SqlHelper.ExecuteNonQuery(SqlServerHelper.connStr, CommandType.Text, sql, null); // here i am getting the result in integer, i want to covert it to datatable.
return table;
}


Please help me this.
Thanks




Responses

Posted by: Ashish.Shrma on: 8/22/2012 [Member] Starter | Points: 25

Up
0
Down
Dim dt As DataTable = New DataTable()

Dim da As SqlDataAdapter = New SqlDataAdapter(sql, UrConnection)
da.Fill(dt)
Return dt


I hope this will help

Ashish

Manikattamuri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nadh123 on: 8/22/2012 [Member] Starter | Points: 25

Up
0
Down
protected DataTable tablenames()
{
SqlConnection sqlcon = new SqlConnection();
//Mentioned Connection string make sure that user id and password sufficient previlages
sqlcon.ConnectionString = @"Server=servername;database=databasename;uid=username;pwd=password;";
string query = "SELECT NAME FROM MASTER..SYSDATABASES";
SqlCommand cmd = new SqlCommand(query, sqlcon);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

Mahendra
91-9908699686

Manikattamuri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Manikattamuri on: 8/22/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Ashish & Nadh123,

I need to achieve this by using DAL layer by using sqlhelper class.
Thanks

Manikattamuri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Megan00 on: 8/22/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Manikattamuri, below code can help you

              int result = 0;

DataTable table = new DataTable();
DataColumn column = new DataColumn("column1", typeof(int));
table.Columns.Add(column);
DataRow row = table.NewRow();
row["column1"] = result;
table.Rows.Add(row);


Never give up! Smile to the world!
http://excelcsharp.blog.com/

Manikattamuri, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response