Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Insert Data In Database

Insert Data In Database

Scheduled Pinned Locked Moved Database
databasewpfsecuritytutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    InvXeesh
    wrote on last edited by
    #1

    Hi i want to know how to Insert Data Into Database table from textbox on button click..? Here's my codes.. namespace DataBindingListBox { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { public SqlConnection connection; public SqlCommand command; string sql = "Select Number From Tnumber"; string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"; public Window1() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { BindData(); } private void BindData() { DataSet dtSet = new DataSet(); using (connection = new SqlConnection(connectionString)) { command = new SqlCommand(sql, connection); SqlDataAdapter adapter = new SqlDataAdapter(); connection.Open(); adapter.SelectCommand = command; adapter.Fill(dtSet, "Tnumber"); listBox1.DataContext = dtSet; } } private void BindXmlData() { //listBox1.DataContext = BooksData ; } private void button1_Click(object sender, RoutedEventArgs e) { } } }

    H 1 Reply Last reply
    0
    • I InvXeesh

      Hi i want to know how to Insert Data Into Database table from textbox on button click..? Here's my codes.. namespace DataBindingListBox { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { public SqlConnection connection; public SqlCommand command; string sql = "Select Number From Tnumber"; string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"; public Window1() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { BindData(); } private void BindData() { DataSet dtSet = new DataSet(); using (connection = new SqlConnection(connectionString)) { command = new SqlCommand(sql, connection); SqlDataAdapter adapter = new SqlDataAdapter(); connection.Open(); adapter.SelectCommand = command; adapter.Fill(dtSet, "Tnumber"); listBox1.DataContext = dtSet; } } private void BindXmlData() { //listBox1.DataContext = BooksData ; } private void button1_Click(object sender, RoutedEventArgs e) { } } }

      H Offline
      H Offline
      himanshu2561
      wrote on last edited by
      #2

      Just read some basic tutorials which ae easily available on google

      himanshu

      I A 2 Replies Last reply
      0
      • H himanshu2561

        Just read some basic tutorials which ae easily available on google

        himanshu

        I Offline
        I Offline
        InvXeesh
        wrote on last edited by
        #3

        I did try to find but didn't get any appropriate tut aur guide.. :((

        H 1 Reply Last reply
        0
        • I InvXeesh

          I did try to find but didn't get any appropriate tut aur guide.. :((

          H Offline
          H Offline
          himanshu2561
          wrote on last edited by
          #4

          string sql = "Insert into "TableName" (Column Name) values('Column Value')"; string connectionString = @"Data Source='local\SQLEXPRESS';Integrated Security=True;Pooling=False;Initial Catalog='MASTER'"; DataSet dtSet = new DataSet(); using (connection = new SqlConnection(connectionString)) { command = new SqlCommand(sql, connection); SqlDataAdapter adapter = new SqlDataAdapter(command); adapter.Fill(dtSet); }

          himanshu

          1 Reply Last reply
          0
          • H himanshu2561

            Just read some basic tutorials which ae easily available on google

            himanshu

            A Offline
            A Offline
            Aman786Singh
            wrote on last edited by
            #5

            Is this himanshu kashyap from amritsar??

            H 1 Reply Last reply
            0
            • A Aman786Singh

              Is this himanshu kashyap from amritsar??

              H Offline
              H Offline
              himanshu2561
              wrote on last edited by
              #6

              yes

              himanshu

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups