Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void button1_Click(object sender, EventArgs e)
    {
        if (comboBoxstaff.Text == string.Empty)
        {
            MessageBox.Show("Please Select gaugeman");  // not to let thecombobox empty
            return;
        }
        else if (comboBoxcompondrubber.Text == string.Empty)
        {
            MessageBox.Show("Please Select Compond Rubber");// not to let thecombobox empty
            return;

        }
        else if (textBox1.Text == string.Empty)
        {
            MessageBox.Show("Please Key in W.S thickness");// not to let thetextbox empty
            return;

        }
        else if (textBox2.Text == string.Empty)
        {
            MessageBox.Show("Please Key in G.S thickness");// not to let thecombobox empty

        }
        SQLiteConnection insertsess = new SQLiteConnection("Data Source=|DataDirectory|\\test1db");
        string insert12 = "INSERT INTO thickness (GaugeMan,Dateandtime, CompondRubber,GSthickness,WSthicknes) VALUES ('" + comboBoxstaff.Text + "','" + label2.Text + "', '" + comboBoxcompondrubber.Text + "', '" + textBox2.Text + "', '" + textBox1.Text + "')";   //insert statment
        SQLiteCommand ins1 = new SQLiteCommand(insert12, insertsess);
        insertsess.Open();
        ins1.ExecuteNonQuery();
        MessageBox.Show("Data had been saved");// showed when the message is being saved

        SQLiteConnection sesscheck = new SQLiteConnection("Data Source=|DataDirectory|\\test1db");
        SQLiteCommand chk1;
        chk1 = sesscheck.CreateCommand();
        chk1.CommandText = "SELECT GaugeMan,Dateandtime, CompondRubber,GSthickness,WSthicknes FROM thickness WHERE CompondRubber = '" + comboBoxcompondrubber.Text.Trim() + "'";
       sesscheck.Open();
        DataTable thicknessTable = new DataTable();
        //DataTable thicknessTable = new DataTable();
        SQLiteDataReader reader = chk1.ExecuteReader();
        thicknessTable.Load(reader);
        //SQLiteDataReader reader1 = chk2.ExecuteReader();
        //thicknessTable.Load(reader1);
        sesscheck.Close();

        dt = new DataTable();
        sda.Fill(dt);
        dataGridView1.DataSource = dt;

    }


What I have tried:

I had tried using data adapter but it didn't work I tried using data reader but I am not sure.

I want to get the value 12.0 to be saved and displayed into data grid view at the moment if I key 12.1 it also works only like 12.0 it will be entered and displayed as 12 at the data grid view
Posted
Updated 6-Jun-18 21:56pm
v2
Comments
CHill60 6-Jun-18 8:13am    
Saying "it didn't work" does not help us to help you. What is the actual problem?
As an aside, do not use concatenated strings to create sql statements - use parameterized queries instead

Quote:
I want to get the value 12.0 to be saved and displayed into data grid view

Do you know that we don't have access to your database ?

C#
string insert12 = "INSERT INTO thickness (GaugeMan,Dateandtime, CompondRubber,GSthickness,WSthicknes) VALUES ('" + comboBoxstaff.Text + "','" + label2.Text + "', '" + comboBoxcompondrubber.Text + "', '" + textBox2.Text + "', '" + textBox1.Text + "')";   //insert statment

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
 
Share this answer
 
v3
See my solution to your post Sql interjection error faced[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900