|
Come on!
What's that catch(Exception ex) thing? There it is. Use the debugger, or show it in a MessageBox, or write it to a log file...
|
|
|
|
|
Can you give an example of your table structure, because the query string doesn't seem right. Is the table you are querying register or user . Personally I think you should be looking to do something like this :- (assumes table where users info is kept is called users, substitute register if that is the correct table)
try
{
string validateq = "SELECT COUNT(userid) FROM users WHERE username = @username AND password = @passwd ";
SqlCommand cmd = new SqlCommand(validateq, con);
cmd.Parameters.AddWithValue("@username", u.UserName);
cmd.Parameters.AddWithValue("@passwd", u.Password);
con.Open();
return Convert.ToInt32(cmd.ExecuteScalar()) > 0;
}
catch (SqlException ex)
{
throw new Exception(ex.Message,ex) ;
}
I hope this helps.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Reason for my vote of one:
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Another reason for a one-vote: one should NOT swallow exceptions, i.e. have a catch block that does not use the information contained in the exception. At least, log it and look at it, that should allow you to solve your problems yourself.
|
|
|
|
|
Luc Pattyn wrote: Another reason for a one-vote: one should NOT swallow exceptions,
Can't disagree more with that.
This forum is "C#", not "Advanced C# Only".
So the fact someone doesn't know how to write exception handling correctly is a reason for correction not down voting.
|
|
|
|
|
if he doesn't know how to deal with an exception, he should not use a try-catch block. The code shown very much resembles an ON ERROR RESUME NEXT statement.
|
|
|
|
|
If I'm not wrong, your query is wrong and your database provider is throwing an exception that your code is swallowing.
select count(*) from register where user.username = @username and user.password = @passwd
must be rewritten as
select count(*) from register where username = @username and password = @passwd
And don't swallow exceptions, log it and/or display it.
|
|
|
|
|
Along with what the others say, I would use ExecuteScalar and simply cast the result.
return ( (int) cmd.ExecuteScalar() > 0 ) ;
And were I to catch the Exception I'd wrap it another Exception with more information. Something along the lines of:
catch (Exception ex)
{
throw ( new System.Data.DataException ( "validateuser unable to find user " + u.username , ex ) ) ;
}
|
|
|
|
|
You need to display the exception in your catch block.
Something like....
System.Console.WriteLine("Exception=" + e);
That will tell you what the error is and what line it shows up on.
|
|
|
|
|
Hi,
I need to display images from a particular path, in which the images are not stored in the data base.
Can anybody help with some sort of code will be very much helpfull for me.
Thanks in advance
|
|
|
|
|
|
Hi,
You can implement the cell paint event. I think that you have a data table like this:
(Val1, Val2, PicturePath, ...).
You can find bellow an example of code that shows in a data grid view a grid contact:
----------------------------------------------------------------
|Picture | First Name | Last Name | Phone number |
----------------------------------------------------------------
| | Mr. X | X1 | 00112233 |
----------------------------------------------------------------
| | Mr. X | X1 | 00112233 |
----------------------------------------------------------------
myDataGridView += new DataGridViewCellPaintingEventHandler(myDataGridView_CellPainting);
void myDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex > 0 && e.ColumnIndex == 0)
{
try
{
string strPath = myDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
Bitmap objPicture = null;
if(dicPictures.ContainsKey(strPath))
{
objPicture = dicPictures[strPath];
}
else
{
objPicture = Bitmap.FromFile(strPath);
dicPictures.Add(strPath, objPicture);
}
e.Graphics.DrawImage(objPicture, e.CellBounds);
}
catch (Exception Error)
{
}
}
}
|
|
|
|
|
Hi Everyone,
I am very new to C# and I wrote this code from the book which compiles and run without any problem. After I execute the program, it give me nothing in the black output screen. I think this program possible need some sort of external file to "act-on." I am really not sure what it needs, the book leaves me hanging (it does say anything an external file or what to name the file). Please kindly help.
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication_test
{
public class Program
{
const int BufferSize = 1024;
public static void Main(string[] args)
{
string tempPath = Path.GetTempFileName();
string tempPath2 = Path.GetTempFileName();
if (File.Exists(tempPath))
{
using (FileStream input = File.OpenRead(tempPath))
{
byte[] buffer = new byte[BufferSize];
int bytesRead;
using (FileStream output = File.OpenWrite(tempPath2))
{
while ((bytesRead = input.Read(buffer, 0, BufferSize)) > 0)
{
output.Write(buffer, 0, bytesRead);
}
}
}
}
}
}
}
Thanks.
|
|
|
|
|
Your code snippet could be properly formatted using pre tags.
The file your program reads is:
string tempPath = Path.GetTempFileName();
The file your program writes is:
string tempPath2 = Path.GetTempFileName();
That's not very useful.
A better solution would be:
string tempPath = args[0];
string tempPath2 = args[1];
And then you'd call it by
ConsoleApplication_test.exe "C:\Temp\inputfile.dat" "C:\Temp\outputfile.dat"
|
|
|
|
|
Bernhard,
Thank you for the explanation, but I am still very unclear on how to execute or call the program. What specifically do i do with:
ConsoleApplication_test.exe "C:\Temp\inputfile.dat" "C:\Temp\outputfile.dat"
Is it one line or two lines?
Where do I type it or put it?
I really just starting out with C# and I not very savvy like seasoned programmers.
Thanks.
Edward.
|
|
|
|
|
Good evening, I am trying to develop an application with c # for sending emails, I developed a small publisher in a solution at hand, and I develop the game of sending mail to a solution by dna, how can I integrate the editor in the area of text that is at the 2 nd solution, is what I added commme reference? and how can I put in the form of the second solution?
|
|
|
|
|
Normally, the code you want to use in the other application would be compiled as a class-library or written as a control of some kind. Then you go to your other project and add a reference to this project. Then you can use the component in your app.
|
|
|
|
|
yes I know but my problem is that I want to add is an editor windows forms in an area at the second windows forms
|
|
|
|
|
Right-click on the "References" folder in your Solution Explorer, and click "Add Reference..."
Then choose the project that contains the editor.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
yes I know but my problem is that I want to add is an editor windows forms in an area at the second windows forms
|
|
|
|
|
OK, so redo your editor project and make it a control instead of a complete form. That way you get the flexibility to add it to any project very easily instead of trying to make a form look like a control.
|
|
|
|
|
|
Repost!!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Congratulations! You found the best possible way to get your question ignored!
|
|
|
|
|
any one send me library mangment project using c# and oracle.
|
|
|
|