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]; } }
}
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 :(
RzBusterCB87 1 month ago