0
public void FillGrid()
{
    string connString = "Server =localhost;Port = 3306; Database =lbmtcs; UID =serverUser; Password =";
    MySqlConnection Pathway = new MySqlConnection(connString);

    string gridView = "SELECT PIN, Status, Cert_Title_No, Owner_Name, Co_Owner, Street, Barangay FROM landrecord"
                        +"WHERE PIN = @pin, Status = @Stat AND Cert_Title_No = @Cert AND Owner_Name = @Owner AND Co_Owner = @CO AND Street = @St AND Barangay = @Bar";
    MySqlCommand grid = new MySqlCommand(gridView, Pathway);
    MySqlDataAdapter MyDA = new MySqlDataAdapter();
    MySqlCommandBuilder cmd = new MySqlCommandBuilder(MyDA);
    MyDA.SelectCommand = grid;

    DataTable table = new DataTable();
    MyDA.Fill(table);

    BindingSource bSource = new BindingSource();
    bSource.DataSource = table;
    dGrid.DataSource = bSource;

}

MySqlException was unhandled:

Fatal error encountered during command execution.

Whats wrong in the code?

I'm selecting some columns to show in my datagrid.

4
  • 1
    for starters I would change the gridView variable to be something like strSQL 2nd where are you creating the Parameters..? Pathway change that to sqlConn clean up your code a bit and use variables that make sense just FYI Commented Sep 17, 2012 at 16:04
  • Do you just want to display data or are you planning on saving and updating etc? Let me know as it changes the answer. Commented Sep 17, 2012 at 16:27
  • thanks dash.. followed what u posted.. this is new error.. cant seem to find the right type.. i used int in my database.. Incorrect format on DbType.. all Int creates this error Commented Sep 17, 2012 at 16:37
  • MySqlParameter parameter = new MySqlParameter() { ParameterName = "@pin", DbType = DbType.Int32, Value = Int32.Parse(txtPin.Text) }; whats wrong with this code? Error is Incorrect FOrmat Commented Sep 17, 2012 at 16:45

1 Answer 1

2

Between @pin and Status should be an AND and not a ,

Sign up to request clarification or add additional context in comments.

1 Comment

changed my code to what u all said.. still same error.. this is what im trying to do. input from textbox ->data to mysql database then datagrid will show whats inside the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.