I have a single SQlite query that returns "10" to me but I couldn't send it to c# textbox1.text area. I found datagrid examples which work just fine but single value for textbox I could not handle it.

I tried changing datagrid areas to textbox but really I have no idea how to get value with sqlite

private SQLiteConnection con = new SQLiteConnection();
    private SQLiteCommand com = new SQLiteCommand();
    private SQLiteDataAdapter adapt = new SQLiteDataAdapter();
    private DataSet ds = new DataSet();
    private DataTable dt = new DataTable();
    //private SQLiteDataReader dr = new SQLiteDataReader();


    public void set_connection()
    {
        con = new SQLiteConnection();
        con.ConnectionString = ("Data Source=data/lastix_db.s3db");
    }

    public void execute_q(string txtQuery)
    {
        set_connection();
        con.Open();
        com = con.CreateCommand();
        com.CommandText = txtQuery;
        com.ExecuteNonQuery();
        con.Close();
    }
    public void load_data()
    {
        set_connection();
        con.Open();
        com = con.CreateCommand();
        string comtext = "SELECT * FROM stok";
        adapt = new SQLiteDataAdapter(comtext, con);
        ds.Reset();
        adapt.Fill(ds);
        dt = ds.Tables[0];
        dataGridView1.DataSource = dt;
        con.Close();
    }

    private void Button2_Click(object sender, EventArgs e)
    {

        set_connection();
        string stokout = "SELECT SUM(giris_adet) - SUM(cikis_adet) as mevcutstok from stok where malzeme_kodu = 651";
        execute_q(stokout);

        label16.Text = Convert.ToString(stokout);

            label16.Text = //must be read "10" from sqlite

Insert update delete and all other datagrid solutions are ok but I'm really stuck on read single data and type it to textbox.

1 Answers

0
Community On
SQLiteConnection connect = new SQLiteConnection();
connect.ConnectionString = ("Data Source=data/lastix_db.s3db");
connect.Open();
string sql = "SELECT SUM(giris_adet) - SUM(cikis_adet) as mevcutstok from stok where malzeme_kodu = 651";
SQLiteCommand cmd = new SQLiteCommand(sql, connect);
Int32 totalp = Convert.ToInt32(cmd.ExecuteScalar());
cmd.Dispose();
baglan.Close();
//MessageBox.Show("Your Balance is: " + totalp);
label16.Text = Convert.ToString(totalp);