|
i am trying and hope i will get it soon. And will get back to u if i need...
|
|
|
|
|
Will this get value dashboardid from table into variable 'str'?
int str = "select dashboardid from dashboardlogin where userid=101";
cmd.CommandText = str;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
cmd.ExecuteNonQuery();
dashboardid is 'int' type in database.
but i have error in first line if i use the above code:
Cannot implicitly convert type 'string' to 'int'.
Do i need to add any other code also for getting its data into variable 'str'?
M new to c#,just learnt connecting database,a student doing project in c#.
plz reply
thank you.
nekshan.
|
|
|
|
|
I recommend giving up on windows forms and databases, and reading a beginners book on C#. Where did you find this code ? If you can't debug it, you're just going to have more and more trouble if you don't take my advice.
Nekshan wrote: int str
str is of type int.
Nekshan wrote: "select dashboardid from dashboardlogin where userid=101";
this is a string
Nekshan wrote: Cannot implicitly convert type 'string' to 'int'.
That is what the error is telling you.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
select dashboardid from dashboardlogin where userid=101;
Gives out a int value : dashboardid is int.
u mean i need to :
string str = "select dashboardid from dashboardlogin where userid=101";
Then convert the result to int?
thanx for the advice, i m already refering a book.
|
|
|
|
|
Nekshan wrote: u mean i need to :
string str = "select dashboardid from dashboardlogin where userid=101";
Yes, your query is a string
Nekshan wrote: Then convert the result to int?
Yes, you need to get an int back from the DB, you will need to convert this value.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
hi ...
you must change your code such as this :
int dashboardid = 10;
string str = "select " + dashboardid.ToString() + " from dashboardlogin where userid=101";
cmd.CommandText = str;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
-- modified at 0:36 Thursday 8th February, 2007
|
|
|
|
|
thank you.
int dashboardid = 10; ???
select query takes dashboardid from database...
|
|
|
|
|
you need to read a beginner book as well. This won't work, you're going to end up with select 10 from dashboardlogin where userid=101 10 is not a valid name for a column, and even if it was, this would not do what the OP wants
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
if you change select query like this , it work correctly
string str = "select [" + dashboardid.ToString() + "] from dashboardlogin where userid=101";
|
|
|
|
|
string str = "select [" + dashboardid.ToString() + "] from dashboardlogin where userid=101";
dashboardid.ToString() is giving error. after dashboardid. -> tostring option does not cum.
how can i convert a string type variable(having value int type) to integer?
can u plz help..
thank you
nekshan.
|
|
|
|
|
Nekshan wrote: dashboardid.ToString() is giving error. after dashboardid. -> tostring option does not cum.
His advice is totally wrong. Don't follow it.
Nekshan wrote: how can i convert a string type variable(having value int type) to integer?
string s = "10"
int n;
if (int.TryParse(s, out n))
{
// n now = 10
}
else
{
s was not a number
}
But, you won't get a single number out of the DB, you'll get a dataset, containing one data table, with a data row for each id that was returned.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
No, you are TOTALLY wrong. dashboardid is a column in his database. 10 is NOT a column in his database.
In fact, you don't need to call tostring when adding a number to a string, but in this case, your core advice is wrong.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
hi Graus,
i m trying this, but it does not seem to work out :
string s = cmd.CommandText = "select dashboardid from dashboardlogin where (loginname = 'nekshan') AND (loginpswd = 'engineer')";
cmd.CommandText = s;
cmd.CommandType = CommandType.Text;
int i = Convert.ToInt32(s); // giving error on this line
cmd.Connection = conn;
cmd.ExecuteNonQuery();
It gives error as : Input string was not in a correct format.
do i need to use dataset for it?
hope to get a reply.
thanx.
|
|
|
|
|
As Christian said before, you should definitely go out and buy you a book on C# and database programming.
Obviously, you still not get the idea that s is just a plain string that contains the text of your query, but the string itself cannot return the result of the query. That's what the classes inside the System.Data namespace are for. You already set up a SqlCommand instance in your code snippet, so why are you still trying to get the query result from the query string.? You should get the id by calling ExecuteScalar instead of ExecuteNonQuery on the SqlCommand instance and cast it to int. Take a look at the MSDN topic of the ExecuteScalar method; it contains an example that is similar to what you're trying to achieve.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
You are totally, utterly lost. If you can't understand what I've explained to you, that proves you're in over your depth. Work through a beginners book then come back to this stuff.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
SqlConnection conn=new SqlConnection("server=(local);Initial Catalog=Northwind;user id=istore;pwd=istore");
conn.Open();
SqlCommand cmd=new SqlCommand("select employeeid from employees where employeeid=1",conn);
Label1.Text=Convert.ToString(cmd.ExecuteScalar());
-------------
this code surely works
try it!!;P
|
|
|
|
|
SqlCommand cmd=new SqlCommand("select employeeid from employees where employeeid=1",conn);
Label1.Text=Convert.ToString(cmd.ExecuteScalar());
employeeid is an int in db.
answer is coming in label, but if i put a variable like dis :
int s = Convert.ToString(cm.ExecuteScalar());it gives error : Cannot implicitly convert type 'string' to 'int'.
if i put variable like:
string s = Convert.ToString(cm.ExecuteScalar());
it gives error : Cannot convert from 'string' to 'int', in the below function.
as i have to display dis employeeid ie 's' in a function:
funEntrylogin(s, tb_id.Text, tb_pswd.Text, DateTime.Now, DateTime.Now);
|
|
|
|
|
Hi!
I have to implement CSS in my C# asp.net web application.
I made a Css class and used it in my aspx form. But formatting is applied only on backgroud of the form. formatting on the web controls like buttons and labels is not applied. Can anyone guide me to solve this problem.
Thanx
|
|
|
|
|
This is not a C# question, it belongs in the web development forum ( as it has nothing to do with ASP.NET, or C# ).
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
anyone have an idea how to concatenate SortedLists? and also get its half?
for example say i have SortedLists s1, s2, s3. I would like to add all the top/end halves of each SortedLists into a single one, say sTotal;
thanks!
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
Please, could anyone send me a C# source code to draw an ellipse by pressing a button?
Thank you very much.
Saludos, Giovanni
|
|
|
|
|
Why would you ask this again, when your original message is two posts down ? Why not read what I suggested ? If you can't follow my explanation, ask me. If you're incapable of writing this yourself, give up on working at this level of complexity and do some work to bring yourself up to this level by studying something more at your level.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
If you believe you are a genius, why don't answer to the specific question?.
Else avoid answer me.
Saludos, Giovanni
|
|
|
|
|
I didn't say I was a genius. I *did* answer your question.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi!
i have to use media player control to play video clips. I have found no control for it. Actually i dont want to code in asp.So can anyone help me in using control and its coding in C#.
waiting for urgent reply.
Thanx
|
|
|
|