Click here to Skip to main content
15,905,785 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: help to implement encryption-based authentication for exchange DEX-TRADE Pin
Member 145001843-May-21 21:39
Member 145001843-May-21 21:39 
Questionhelp to implement encryption-based authentication for exchange btc-alpha Pin
Member 145001841-May-21 0:04
Member 145001841-May-21 0:04 
QuestionOpenSSL Signing with RSA key in Dot Net on Windows Pin
David Carta28-Apr-21 14:18
professionalDavid Carta28-Apr-21 14:18 
AnswerRe: OpenSSL Signing with RSA key in Dot Net on Windows Pin
Richard Andrew x643-May-21 10:34
professionalRichard Andrew x643-May-21 10:34 
QuestionC# .Net Core error : server error in '/' application Pin
Member 1514832212-Apr-21 7:09
Member 1514832212-Apr-21 7:09 
AnswerRe: C# .Net Core error : server error in '/' application Pin
Richard MacCutchan12-Apr-21 8:09
mveRichard MacCutchan12-Apr-21 8:09 
AnswerRe: C# .Net Core error : server error in '/' application Pin
Member 1514832212-Apr-21 8:27
Member 1514832212-Apr-21 8:27 
AnswerRe: C# .Net Core error : server error in '/' application Pin
Richard Deeming12-Apr-21 21:26
mveRichard Deeming12-Apr-21 21:26 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Member 1514832212-Apr-21 22:37
Member 1514832212-Apr-21 22:37 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Richard Deeming12-Apr-21 22:55
mveRichard Deeming12-Apr-21 22:55 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Member 1514832213-Apr-21 0:02
Member 1514832213-Apr-21 0:02 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Richard Deeming13-Apr-21 0:24
mveRichard Deeming13-Apr-21 0:24 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Member 1514832213-Apr-21 0:51
Member 1514832213-Apr-21 0:51 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Richard Deeming13-Apr-21 1:21
mveRichard Deeming13-Apr-21 1:21 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Member 1514832212-Apr-21 23:49
Member 1514832212-Apr-21 23:49 
AnswerRe: C# .Net Core error : server error in '/' application Pin
C0ding_j3ff18-Apr-21 10:54
C0ding_j3ff18-Apr-21 10:54 
Generalsql server, database stored procedure not working with ip address, please help. Pin
Member 1472928712-Apr-21 0:38
Member 1472928712-Apr-21 0:38 
AnswerRe: sql server, database stored procedure not working with ip address, please help. Pin
Richard Deeming12-Apr-21 2:13
mveRichard Deeming12-Apr-21 2:13 
GeneralRe: sql server, database stored procedure not working with ip address, please help. Pin
Dave Kreskowiak12-Apr-21 4:03
mveDave Kreskowiak12-Apr-21 4:03 
GeneralRe: sql server, database stored procedure not working with ip address, please help. Pin
Richard Deeming12-Apr-21 4:41
mveRichard Deeming12-Apr-21 4:41 
GeneralRe: sql server, database stored procedure not working with ip address, please help. Pin
C0ding_j3ff18-Apr-21 10:55
C0ding_j3ff18-Apr-21 10:55 
QuestionWhy am I getting insufficient parameters supplied Pin
Adrian Rowlands24-Mar-21 9:57
Adrian Rowlands24-Mar-21 9:57 
QuestionRe: Why am I getting insufficient parameters supplied Pin
Eddy Vluggen24-Mar-21 10:35
professionalEddy Vluggen24-Mar-21 10:35 
AnswerRe: Why am I getting insufficient parameters supplied Pin
Dave Kreskowiak24-Mar-21 10:56
mveDave Kreskowiak24-Mar-21 10:56 
First, clean up your code indentation. It makes debugging your code easier and reduces the number of bugs in your code.

Next, in your SQL statement, get rid of the period you have on the FROM clause. Then get rid of the * and replace it with the fields you want. Trust me, using "SELECT *" is NOT a habit you want to get into.
SELECT fieldList, ... FROM customer WHERE lastname=@setName";
After that, why are you creating a SqlCommand object only to throw it out and never use it with the DataAdapter? The SqlDataAdapter will take a SqlCommand object as a parameter, but you just pass in the SQL statement (.Text property) of the command you built, effectively ignoring the parameter object you built.

Your code should be this:
C#
using (SQLiteCommand cmd = conn.CreateCommand())
{
    try
    {
        cmd.CommandText = @"SELECT * FROM customer WHERE lastname = @setName";

        cmd.Parameters.AddWithValue("@setName", txt_name.Text);
    
        da_Customer = new SQLiteDataAdapter(cmd);
        dt_Customer = new DataTable();
        da_Customer.Fill(dt_Customer);
        dgv_customer.DataSource = dt_Customer;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
Also, it seems you're using class global data objects, "da_Customer", "dt_Customer", ... This is a REALLY BAD IDEA and will get you into trouble in the future with bugs that are really difficult to find.

You should have individual methods that will return data, creating and disposing their own database objects, more like this:
C#
public DataTable GetCustomerTableFromLastName(string lastName)
{
    using (SQLiteConnection conn = new SQLiteConnection(CONNECTIONSTRING))
    {
        SQLiteCommand comm = conn.CreateCommand();

        cmd.CommandText = @"SELECT firstname, lastname, something, somethingElse FROM customer WHERE lastname = @setName";

        cmd.Parameters.AddWithValue("@setName", txt_name.Text);
    
        SQLiteDataAdapter adpat = new SQLiteDataAdapter(cmd);
        DataTable tableResult = new DataTable();
        adapt.Fill(tableResult);

        return tableResult;
    }
}
But, even though this is an improvement, it still falls way short of production quality code.


modified 25-Mar-21 9:20am.

AnswerRe: Why am I getting insufficient parameters supplied Pin
Richard Deeming24-Mar-21 22:07
mveRichard Deeming24-Mar-21 22:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.