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.Sql; using System.Data.SqlClient; using System.Data.SqlTypes; namespace TextAdd3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //This line simply shows in a datagridview me that data is being found this.table1TableAdapter.Fill(this.database1DataSet.Table1); } private void button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\bin\\Debug\\Database1.mdf;Integrated Security=True;User Instance=True"); con.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO Table1 (name, url) VALUES (@name, @url)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@name", SqlDbType.VarChar); cmd.Parameters["@name"].Value = textBox1.Text; cmd.Parameters.Add("@url", SqlDbType.VarChar); cmd.Parameters["@url"].Value = textBox2.Text; cmd.ExecuteNonQuery(); con.Close(); this.table1TableAdapter.Fill(this.database1DataSet.Table1); } private void button2_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\bin\\Debug\\Database1.mdf;Integrated Security=True;User Instance=True"); con.Open(); string sql = ("SELECT * FROM TABLE1"); DataSet ds1 = new DataSet(); SqlDataAdapter dAdap = new SqlDataAdapter(sql, con); dAdap.Fill(ds1, "Table1"); SqlCommandBuilder cBuild = new SqlCommandBuilder(dAdap); DataRow dRow = ds1.Tables["Table1"].NewRow(); dRow[0] = textBox1.Text; dRow[1] = textBox2.Text; ds1.Tables["Table1"].Rows.Add(dRow); dAdap.Update(ds1, "Table1"); con.Close(); this.table1TableAdapter.Fill(this.database1DataSet.Table1); } } }
AttachDbFilename=|DataDirectory|\\bin\\Debug\\Database1.mdf
|DataDirectory|
AttachDbFilename=C:\\Database1.mdf
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)