none
Dataset Updating but DB Table not?

    Question

  •  

    I am trying to insert data into a db but it is not working.  The form works fine and the data shows in the datagridview when I click on the button but it is not inserted into the db.

    DB = sql server 2005 express

    pk = DealNum:int

    reason: nvarchar

    vendorname: nvarchar

    amount: decimal

    AcctNum: int

    datesubmitted: nvarchar

     

    Here is the code for the form:

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;

    using System.Data.SqlClient;

    using System.Data.Sql;

    using System.Configuration;

     

    namespace PaidLookUp

    {

    public partial class Display : Form

    {

    public Display()

    {

    InitializeComponent();

    }

    private void insertDB()

    {

    string aReason = comboBox1.Text;

    int aDealNum = Convert.ToInt32(textBox3.Text);

    string avendor = textBox4.Text;

    decimal aAmount = Convert.ToDecimal(textBox2.Text);

    int aAcctNum = Convert.ToInt32(comboBox2.Text);

    string aDate = textBox1.Text;

    string conn = System.Configuration.ConfigurationSettings.AppSettings["DBConn"];

    string strInsert = "INSERT INTO Deal (DealNum , Reason ,VendorName, Amount , CertcoNum , DateSubmitted) VALUES ( " + aDealNum + " , '" + aReason + "' , '" + avendor + "' , " + aAmount + "," + aAcctNum + " , '" + aDate + "' )";

    SqlConnection sqlConn = new SqlConnection(conn);

    SqlCommand insertCmd = new SqlCommand(strInsert, sqlConn);

    sqlConn.Open();

    try

    {

    int i;

    i = insertCmd.ExecuteNonQuery();

    MessageBox.Show(i.ToString());

    }

    catch (SqlException)

    {

    MessageBox.Show("Error");

    }

    sqlConn.Close();

    }

    private void Display_Load(object sender, EventArgs e)

    {

    string adate = DateTime.Today.ToShortDateString();

    textBox1.Text = adate;

    dataGridView1.DataSource = dealTableAdapter1.GetAll();

    bindingNavigator1.BindingSource = paidLookUpDataSetBindingSource;

    }

    private void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e)

    {

    //bindingNavigator1.MoveNextItem;

    }

    private void bindingNavigatorMovePreviousItem_Click(object sender, EventArgs e)

    {

    //bindingNavigator1.MovePreviousItem;

    }

    private void bindingNavigatorMoveFirstItem_Click(object sender, EventArgs e)

    {

    //bindingNavigator1.MoveFirstItem;

    }

    private void bindingNavigatorMoveLastItem_Click(object sender, EventArgs e)

    {

    //bindingNavigator1.MoveLastItem;

    }

    private void button1_Click(object sender, EventArgs e)

    {

    insertDB();

    dataGridView1.DataSource = null;

    dataGridView1.DataSource = dealTableAdapter1.GetAll();

    }

    }

    }

    Thursday, May 15, 2008 10:49 PM

Answers

All replies