Search
Hall of Fame
About Us
All Questions
New Question
Login
C# .NET - hi friends i m using wpf
Asked By
malatesh swadi
on 03-May-12 03:13 AM
hi friends,
i m using c# using wpf i have written the mssql query in c# like this
string strqry = "select count(type) from tbluser where type='admin'";
and i need the count value in a varible
can any one help me....
dipa ahuja
replied to
malatesh swadi
on 03-May-12 03:21 AM
void
getData()
{
SqlConnection
conn =
new
SqlConnection
(
"connstring"
);
SqlCommand
comm =
new
SqlCommand
(
"select count(type) from tbluser where type='admin'"
, conn);
conn.Open();
textBox1.Text = comm.ExecuteScalar().ToString();
conn.Close();
}
Venkat K
replied to
malatesh swadi
on 03-May-12 05:48 AM
Hi
use cmd.ExecuteScalar()
to get the result
SqlConnection connection = new SqlConnection(myConnectionString);
SqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "select count(type) from tbluser where type='admin'";
int result = ((int)cmd.ExecuteScalar()); connection.Close();
Thanks
malatesh swadi
replied to
dipa ahuja
on 03-May-12 07:13 AM
thanks..
ODBC Drivers for QuickBooks, Salesforce, SAP, MSCRM, SharePoint … Free Trial!