c# database - dataGridView

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
2,798
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Oct 28, 2011

code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication3
{ public partial class Form1 : Form { DataSet ds = new DataSet(); SqlConnection con = new SqlConnection("Data Source= cot-57f2fb0a194; Initial Catalog= login2;Integrated Security=TRUE"); SqlDataAdapter da = new SqlDataAdapter(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { da.InsertCommand = new SqlCommand("insert into login values(@name,@pass)", con); da.InsertCommand.Parameters.Add("@name", SqlDbType.VarChar).Value = textBox1.Text; da.InsertCommand.Parameters.Add("@pass", SqlDbType.VarChar).Value = textBox2.Text; con.Open(); //MessageBox.Show(con.State.ToString()); da.InsertCommand.ExecuteNonQuery(); con.Close(); } private void button2_Click(object sender, EventArgs e) { da.SelectCommand=new SqlCommand("select * from login",con); ds.Clear();//what is this ? I show you. da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } }
}

Category:

Education

Tags:

License:

Standard YouTube License

  • likes, 1 dislikes

Link to this comment:

Share to:
see all

All Comments (1)

Sign In or Sign Up now to post a comment!
  • My database that I created with the database wizzard stopped working aafter trying your method of adding to the database...

    I had a datagridview to edit data and save data, but then it always blank now after trying your method on it for adding data from text boxes...

    It only remember the row amounts, not the data in the rows anymore...fail

    Only fix so far is deleting the whole database from the form and remaking it again with the wizzard and new datagridview...fail :(

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more