get value from database into a variable
-
Will this get value dashboardid from table into variable 'str'? int str = "select dashboardid from dashboardlogin where userid=101"; dashboardid is 'int' type in database. but i have error if i use this: Cannot implicitly convert type 'string' to 'int'. do i need to add any other code also for getting its data into variable 'str'? plz reply thank you. nekshan.
-
Will this get value dashboardid from table into variable 'str'? int str = "select dashboardid from dashboardlogin where userid=101"; dashboardid is 'int' type in database. but i have error if i use this: Cannot implicitly convert type 'string' to 'int'. do i need to add any other code also for getting its data into variable 'str'? plz reply thank you. nekshan.
hey this is wrong , either u write a stored procedured which will return a parameters from stored procedures.. or execute the query. get the result set in to datatable and get ur value from there.
Ravi Kant Srivastava (System Analyst) HandsOn Technology & Engineering Gurgaon (India) e-mail:ravikant@hte.co.in
-
Will this get value dashboardid from table into variable 'str'? int str = "select dashboardid from dashboardlogin where userid=101"; dashboardid is 'int' type in database. but i have error if i use this: Cannot implicitly convert type 'string' to 'int'. do i need to add any other code also for getting its data into variable 'str'? plz reply thank you. nekshan.
Your statement getsthe query string into the string variable
str
. The compiler error occurs, becausestr
is declared as anint
. If you want to use LINQ to query the datasource, try this article: http://www.codeproject.com/useritems/SudokuSolver.asp[^] Otherwise you have to connect to the database and query it with anSqlCommand
:using (SqlCommand selectCommand = new SqlCommand("select dashboardid from dashboardlogin where userid=101", connection)) { object objResult = selectCommand.ExecuteScalar(); if (objResult != null) { int str = (int)objResult; } }
____________________________________ There is no proof for this sentence.
-
Will this get value dashboardid from table into variable 'str'? int str = "select dashboardid from dashboardlogin where userid=101"; dashboardid is 'int' type in database. but i have error if i use this: Cannot implicitly convert type 'string' to 'int'. do i need to add any other code also for getting its data into variable 'str'? plz reply thank you. nekshan.
You got it all wrong. Please read a database tutorial. Just a hint. Someone must execute the desired sql command , don't you think? Its just as you have written
int a="Hello World";
the you just happen to have for text an a sql command. Read the db tutorial.