|
What values does this method return? You're catching the exception but not doing anything with it (apart from changing the return value). Assuming you're using VS, set a breakpoint on the line "return 0;" and check to see that the value of 'e' (the exception) is.
It definitely isn't definatley
|
|
|
|
|
i debuggged the code
but no exception is caught
may be prob with insert statemnt???
any prob with insert query?????
String query = "insert into mydb(username,password) values('" + textBox1.Text + "','" + textBox2.Text + "')";
This code was posted by me...
|
|
|
|
|
Try changing your code to this:
SqlConnection con = connection();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
cmd.Dispose();
and see if you get an exception - if the insert has failed, the database should indicate this.
It definitely isn't definatley
|
|
|
|
|
With regards to the query, I meant the actual string value that is being passed to the database, rather than the statement you use to construct it. Incidentally, is 'mydb' the name of the table or the name of a database containing the table (i.e. should it actually be "insert into mydb.dbo.mytable..."?).
What about the rest of the questions I asked? Have you tried running a profiler on the database to see if the query is actually received. Does the c# statement actually exectute?
It definitely isn't definatley
|
|
|
|
|
no exception is caught
i don knwo where is the problem
what is the meaning of this
"Have you tried running a profiler on the database to see if the query is actually received. "
This code was posted by me...
|
|
|
|
|
A database profiler is a tool which monitors a database and reports back when certain events occur, such as connections to the database, queries, triggers etc. SQL Server comes with its own profiler called (originally enough) SQL Server Profiler - I don't tend to use other databases but I'm sure there are similar tools available for other platforms.
It definitely isn't definatley
|
|
|
|
|
do we use cmd.ExecuteNonQuery()
for inserting??
This code was posted by me...
|
|
|
|
|
Yes that's fine. Broadly speaking, you use ExecuteNonQuery() to execute a SQL statement that doesn't return a result set, ExecuteQuery() to execute a statement that returns tabular data and ExecuteScalar() to execute a query which returns a single value (i.e. if you've done a count(*) or other scalar operation).
It definitely isn't definatley
|
|
|
|
|
If you want a meaningful response, you're going to have to be a lot more specific.
What exception are you getting? What line is triggering it? What query are you sending?
We're programmers, not psychics.
|
|
|
|
|
no exception is caught
insert query is
String query = "insert into mydb values('" + textBox1.Text + "','" + textBox2.Text + "')";
This code was posted by me...
|
|
|
|
|
Good Day Vivek
Today was a long day, and seing this kind of post in the forums bores me to death. First of all when you post something here on codeproject you must use the pre tags so that the code will be formated well and it can differ from your message. secondly we cant know the problem until we see what is contained in the variable "query" , and another thing there is a bad coding practise in your code, you start returning without closing the connection.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
i don feel that pasting the code for close is necessary....
This code was posted by me...
|
|
|
|
|
Then i cant help
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
no need tnx
This code was posted by me...
|
|
|
|
|
Vivek Vijayan wrote: i don feel that pasting the code for close is necessary....
Your right, it is not necessary... when you provide a better description of what the problem is. But as everyone is having to guess how bad your code is, people are going to ask questions.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
this community is for helping not for findng mistakes only
This code was posted by me...
|
|
|
|
|
Vivek Vijayan wrote: this community is for helping not for findng mistakes only
Finding mistakes is helping
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I would say you have a compile error for no catch/finally block but that's the best I can give you for the example you have shown...
Oh, no wait... it's coming to me... 'the.. answer.. is.. .. ..' ..Damn, lost it!
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
if i am writing code for try{}
i know how to write catch and finally
tnx
This code was posted by me...
|
|
|
|
|
Vivek Vijayan wrote: if i am writing code for try{}
i know how to write catch and finally
Er... Where is the logic in that?
you are writing code for database insert but that evidently does not mean you know how to write it
And it's a good example of why your need to make your example better in order to get a good response - you didn't put the catch/finally in your example so how do I know that is not your error?!
Hmmm... a little thought can go a long way.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
|
To get the path of your executable:
System.Reflection.Assembly.GetEntryAssembly().Location
Then just get the directory with System.IO.Path.GetDirectoryName(), and use System.IO.Path.Combine() to tack on the PDF filename.
(Better to use System.IO.Path than string parsing, to make sure it'll work regardless of the location... forward slashes / backslashes, etc)
|
|
|
|
|
Use the code below. Application.StartupPath gives you the path of executable
Process.Start(Application.StartupPath + @"\sample.pdf");
|
|
|
|
|
Or you could try this: (assuming the PDF file will always be in the same directory as your application executable)
Process.Start(Environment.CurrentDirectory + @"\file.pdf");
Hope this helps.
Regards,
Jason Pezzimenti.
If you liked the answer that I have provided, then please click the 'Good Answer' link on the bottom-right of this post. Thank you.
|
|
|
|
|
i have devloped windows application
i want to create linces key
and user should enter key while setup
and also how do i specify the duration like trial version for 1 month
|
|
|
|