473,408 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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):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();

}

}
Attached Images
File Type: jpg Untitled.jpg (38.5 KB, 169 views)
Sep 7 '10 #1
2 1798
mzmishra
390 Expert 256MB
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.
Sep 7 '10 #2
i have entered 1 chr
but still face the same problem
Sep 9 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: CSDunn | last post by:
Hello, I have a combo box designed to look up records in a subform based on the selection made in the combo box. The Record Source for the combo box is a SQL Server 2000 View. There is one bound...
2
by: David Savageau | last post by:
Can anyone help with the following problem? The solution will likely be elementary to many members of this newsgroup, but, Duh! I've been struggling to find it all day. On an Access 2000 form...
11
by: Dave | last post by:
Hi, I have a combo box (Named: Ethnicity) and a field (Named: OtherEthnicity). From the combo drop down list when Other is selected, I want the field next to it to be enabled when the selection...
3
by: Jan Nielsen | last post by:
Hi I have a form with a combo on it The combos items is a list of groups (ie coworker, parent, friend) which it gets from a dataset when the form loads. When the user selects a group from the...
6
by: Ron L | last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying to display in a datagrid. This datasource has 4 columns that I am interested in here, a text column and 3 value columns...
3
by: mf193 | last post by:
Hi, I have a table of around 1000 rows; patient records. Each row is individually defined by a Patient ID number which is my primary key. I have made a simple form to display patient information...
2
by: biganthony via AccessMonster.com | last post by:
Hi, I decided to install Office 2003 Service Pack 3 on my home computer to test (in full knowledge that there may be some issues with it). After installation, I have noticed that with a small...
6
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help with a combo box and this same code works on my first tab with a combo box. The error or problem i have is this code causes an index out of range error when i run it on my second combo...
1
by: kuttans | last post by:
The following is the code i used to load a combo using javascript xmlDoc=document.implementation.createDocument("","",null); xmlDoc.async="false";xmlDoc.preserveWhiteSpace=true;...
4
by: Karl | last post by:
Using A2000 with 2 tables Table 1 is a reference table with 2 fields Table 2 has 2 fields and 2 combo boxes to lookup date in table 1 Combo1 binds to col 1 in table 1, this works OK Combo 2...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.