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

.NET (Core and Framework)

 
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 
AnswerRe: Why am I getting insufficient parameters supplied Pin
C0ding_j3ff18-Apr-21 10:56
C0ding_j3ff18-Apr-21 10:56 
QuestionMessage Removed Pin
18-Mar-21 11:51
Esmera18-Mar-21 11:51 
AnswerMessage Removed Pin
18-Mar-21 15:11
mveDave Kreskowiak18-Mar-21 15:11 
QuestionCreating an invoice in Asp.net core Pin
Member 145665206-Mar-21 9:56
Member 145665206-Mar-21 9:56 
AnswerRe: Creating an invoice in Asp.net core Pin
Eddy Vluggen6-Mar-21 10:12
professionalEddy Vluggen6-Mar-21 10:12 
QuestionEasing the pain of updating code - Excel macros Pin
Roy935-Mar-21 20:36
Roy935-Mar-21 20:36 
AnswerRe: Easing the pain of updating code - Excel macros Pin
Dave Kreskowiak6-Mar-21 5:23
mveDave Kreskowiak6-Mar-21 5:23 
GeneralRe: Easing the pain of updating code - Excel macros Pin
Roy936-Mar-21 8:02
Roy936-Mar-21 8:02 
AnswerRe: Easing the pain of updating code - Excel macros Pin
Mycroft Holmes6-Mar-21 11:14
professionalMycroft Holmes6-Mar-21 11:14 
GeneralRe: Easing the pain of updating code - Excel macros Pin
Roy936-Mar-21 12:56
Roy936-Mar-21 12:56 
GeneralRe: Easing the pain of updating code - Excel macros Pin
Mycroft Holmes6-Mar-21 15:16
professionalMycroft Holmes6-Mar-21 15:16 
AnswerRe: Easing the pain of updating code - Excel macros Pin
Lex Goodies16-Mar-21 14:55
Lex Goodies16-Mar-21 14:55 
QuestionCultureAwareComparer deserialization on .NET 4.6 Pin
Member 1508036222-Feb-21 15:54
Member 1508036222-Feb-21 15:54 
AnswerRe: CultureAwareComparer deserialization on .NET 4.6 Pin
Richard Andrew x6423-Feb-21 14:06
professionalRichard Andrew x6423-Feb-21 14:06 
QuestionSOAP xml Formatting Pin
Member 1508036222-Feb-21 15:51
Member 1508036222-Feb-21 15:51 
AnswerRe: SOAP xml Formatting Pin
Dave Kreskowiak22-Feb-21 17:30
mveDave Kreskowiak22-Feb-21 17:30 

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.