Combo Box using SQL problem in C sharp

Discussion in 'C#' started by Maher Baloch, Sep 7, 2010.

  1. Maher Baloch

    Maher Baloch New Member

    Joined:
    Sep 7, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hey i'm using C Sharp with Sql Server 2005
    i have created two table which are as

    table 1( CardType): Cardcode, Description.
    table 2(CreditCard):Cardcode,number, expirationdate,SecCode.

    the both the table having relation between them of Cardcode.

    but when i used Combo box in C sharp to display the value of CardType.description it work
    but when i want to save the value of cardType.description to creditcard.cardcode it is not working
    can anybody over here tell me how itz work

    public partial class CreditCard : Form
    {
    public CreditCard()
    {
    InitializeComponent();
    }

    private void CreditCard_Load(object sender, EventArgs e)
    {
    // TODO: This line of code loads data into the 'inFlowDataSet.Card_Type' table. You can move, or remove it, as needed.
    this.card_TypeTableAdapter.Fill(this.inFlowDataSet .Card_Type);

    }

    private void button1_Click(object sender, EventArgs e)
    {
    string ConnectionString = "Data source=MAHER-PC\\SQLEXPRESS1;Initial Catalog=inFlow;Integrated Security=true";
    SqlConnection MyConnection = new SqlConnection(ConnectionString);

    string SQLquery = "Insert into Credit_Card(Card_code,number,Expiration_Date,Sec_C ode)";
    SQLquery += " values(@Card_code,@number,@Expiration_Date,@Sec_Co de)";

    try
    {
    MyConnection.Open();
    SqlCommand Cmd = new SqlCommand(SQLquery, MyConnection);
    Cmd.Parameters.AddWithValue("@Card_code", card_TypeTableAdapter = CreditCard.Card_code comboBox1.Text.ToString());
    Cmd.Parameters.AddWithValue("@number", Convert.ToInt64(textBox1.Text));
    Cmd.Parameters.AddWithValue("@Expiration_Date", textBox2.Text);
    Cmd.Parameters.AddWithValue("@Sec_Code", (textBox3.Text).ToUpper());
    Cmd.ExecuteNonQuery();
    MessageBox.Show("records successfully added", "Howdy", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    Close();
    }
    catch (SqlTruncateException sqlTruncateEx)
    {
    MessageBox.Show(sqlTruncateEx.Message);
    }
    catch (SqlTypeException sqlTypeEx)
    {
    MessageBox.Show(sqlTypeEx.Message);
    }


    catch (Exception er)
    {
    MessageBox.Show(er.Message);


    //}

    finally
    {

    MyConnection.Close();

    }

    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice