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

.NET (Core and Framework)

 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Member 1514832213-Apr-21 1:02
Member 1514832213-Apr-21 1:02 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Richard Deeming13-Apr-21 1:24
mveRichard Deeming13-Apr-21 1:24 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Member 1514832213-Apr-21 1:51
Member 1514832213-Apr-21 1:51 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Richard Deeming13-Apr-21 2:21
mveRichard Deeming13-Apr-21 2:21 
GeneralRe: C# .Net Core error : server error in '/' application Pin
Member 1514832213-Apr-21 0:49
Member 1514832213-Apr-21 0:49 
AnswerRe: C# .Net Core error : server error in '/' application Pin
C0ding_j3ff18-Apr-21 11:54
C0ding_j3ff18-Apr-21 11:54 
Generalsql server, database stored procedure not working with ip address, please help. Pin
Member 1472928712-Apr-21 1:38
Member 1472928712-Apr-21 1:38 
AnswerRe: sql server, database stored procedure not working with ip address, please help. Pin
Richard Deeming12-Apr-21 3:13
mveRichard Deeming12-Apr-21 3:13 
GeneralRe: sql server, database stored procedure not working with ip address, please help. Pin
Dave Kreskowiak12-Apr-21 5:03
mveDave Kreskowiak12-Apr-21 5:03 
GeneralRe: sql server, database stored procedure not working with ip address, please help. Pin
Richard Deeming12-Apr-21 5:41
mveRichard Deeming12-Apr-21 5:41 
GeneralRe: sql server, database stored procedure not working with ip address, please help. Pin
C0ding_j3ff18-Apr-21 11:55
C0ding_j3ff18-Apr-21 11:55 
QuestionWhy am I getting insufficient parameters supplied Pin
Adrian Rowlands24-Mar-21 10:57
Adrian Rowlands24-Mar-21 10:57 
QuestionRe: Why am I getting insufficient parameters supplied Pin
Eddy Vluggen24-Mar-21 11:35
professionalEddy Vluggen24-Mar-21 11:35 
AnswerRe: Why am I getting insufficient parameters supplied Pin
Dave Kreskowiak24-Mar-21 11:56
mveDave Kreskowiak24-Mar-21 11: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 23:07
mveRichard Deeming24-Mar-21 23:07 
AnswerRe: Why am I getting insufficient parameters supplied Pin
C0ding_j3ff18-Apr-21 11:56
C0ding_j3ff18-Apr-21 11:56 
QuestionMessage Removed Pin
18-Mar-21 12:51
Esmera18-Mar-21 12:51 
AnswerMessage Removed Pin
18-Mar-21 16:11
mveDave Kreskowiak18-Mar-21 16:11 
QuestionCreating an invoice in Asp.net core Pin
Member 145665206-Mar-21 10:56
Member 145665206-Mar-21 10:56 
AnswerRe: Creating an invoice in Asp.net core Pin
Eddy Vluggen6-Mar-21 11:12
professionalEddy Vluggen6-Mar-21 11:12 
QuestionEasing the pain of updating code - Excel macros Pin
Roy935-Mar-21 21:36
Roy935-Mar-21 21:36 
AnswerRe: Easing the pain of updating code - Excel macros Pin
Dave Kreskowiak6-Mar-21 6:23
mveDave Kreskowiak6-Mar-21 6:23 
GeneralRe: Easing the pain of updating code - Excel macros Pin
Roy936-Mar-21 9:02
Roy936-Mar-21 9:02 
AnswerRe: Easing the pain of updating code - Excel macros Pin
Mycroft Holmes6-Mar-21 12:14
professionalMycroft Holmes6-Mar-21 12:14 
GeneralRe: Easing the pain of updating code - Excel macros Pin
Roy936-Mar-21 13:56
Roy936-Mar-21 13:56 

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.