Combo Box using SQL problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Maher Baloch
    New Member
    • Sep 2010
    • 2

    Combo Box using SQL problem

    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):C ardcode,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.descri ption it work
    but when i want to save the value of cardType.descri ption to creditcard.card code it is not working
    can anybody over here tell me how itz work

    public partial class CreditCard : Form
    {
    public CreditCard()
    {
    InitializeCompo nent();
    }

    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_TypeT ableAdapter.Fil l(this.inFlowDa taSet.Card_Type );

    }

    private void button1_Click(o bject sender, EventArgs e)
    {
    string ConnectionStrin g = "Data source=MAHER-PC\\SQLEXPRESS1 ;Initial Catalog=inFlow; Integrated Security=true";
    SqlConnection MyConnection = new SqlConnection(C onnectionString );

    string SQLquery = "Insert into Credit_Card(Car d_code,number,E xpiration_Date, Sec_Code)";
    SQLquery += " values(@Card_co de,@number,@Exp iration_Date,@S ec_Code)";

    try
    {
    MyConnection.Op en();
    SqlCommand Cmd = new SqlCommand(SQLq uery, MyConnection);
    Cmd.Parameters. AddWithValue("@ Card_code", card_TypeTableA dapter = 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.ExecuteNonQ uery();
    MessageBox.Show ("records successfully added", "Howdy", MessageBoxButto ns.OK, MessageBoxIcon. Exclamation);
    Close();
    }
    catch (SqlTruncateExc eption sqlTruncateEx)
    {
    MessageBox.Show (sqlTruncateEx. Message);
    }
    catch (SqlTypeExcepti on sqlTypeEx)
    {
    MessageBox.Show (sqlTypeEx.Mess age);
    }


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


    //}

    finally
    {

    MyConnection.Cl ose();

    }

    }
    Attached Files
    Last edited by Maher Baloch; Sep 7 '10, 08:48 AM. Reason: adding picture
  • mzmishra
    Recognized Expert Contributor
    • Aug 2007
    • 390

    #2
    From your attached image error message this appears you are trying to insert a string with more characters than the column can maximal accommodate. You must either shorten the string to be isnerted to widen the column.

    Comment

    • Maher Baloch
      New Member
      • Sep 2010
      • 2

      #3
      i have entered 1 chr
      but still face the same problem

      Comment

      Working...