rati sturua

rati sturua

  • NA
  • 1
  • 613

database conecting c# 2015

Sep 30 2015 4:56 AM
i am Beginner programmer i wont to Connect database to windows form (textbox1,textbox2)
.my kod.not works
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'database1DataSet.Students' table. You can move, or remove it, as needed.
this.studentsTableAdapter.Fill(this.database1DataSet.Students);
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection();//?????????????????????????????????????????
try
{
string sql = "INSSERT INTO Students(Student_Id,Studentname) values(" + textBox1.Text+",'"+textBox2.Text+")";
SqlCommand exeSql = new SqlCommand(sql, cn);
cn.Open();
exeSql.ExecuteNonQuery();
}
catch(Exception ex)
{
}
finally
{
}
}
}
}
 

Answers (2)