Click here to Skip to main content
15,913,610 members
Home / Discussions / C#
   

C#

 
GeneralRe: populating combo box on selectedindex changedevent of other combo box1 Pin
Nisar Inamdar10-Jul-07 20:56
Nisar Inamdar10-Jul-07 20:56 
GeneralRe: populating combo box on selectedindex changedevent of other combo box1 Pin
monuSaini10-Jul-07 21:04
monuSaini10-Jul-07 21:04 
GeneralRe: populating combo box on selectedindex changedevent of other combo box1 Pin
Nisar Inamdar10-Jul-07 21:15
Nisar Inamdar10-Jul-07 21:15 
GeneralRe: populating combo box on selectedindex changedevent of other combo box1 Pin
monuSaini10-Jul-07 21:27
monuSaini10-Jul-07 21:27 
GeneralRe: populating combo box on selectedindex changedevent of other combo box1 Pin
Nisar Inamdar10-Jul-07 22:25
Nisar Inamdar10-Jul-07 22:25 
GeneralRe: populating combo box on selectedindex changedevent of other combo box1 Pin
valerian.precop10-Jul-07 21:25
valerian.precop10-Jul-07 21:25 
GeneralRe: populating combo box on selectedindex changedevent of other combo box1 Pin
monuSaini10-Jul-07 21:46
monuSaini10-Jul-07 21:46 
QuestionException Pin
sangramkp10-Jul-07 19:27
sangramkp10-Jul-07 19:27 
My code looks like this:

List<string> items;
private void button2_Click(object sender, EventArgs e)
{
//finalize button click
items = new List<string>();
for (int i = 0; i < passagelistBox.Items.Count; i++)
{
items.Add(passagelistBox.Items[i].ToString());
}
foreach (string currentitem in items)
{
DoInsertData(currentitem.Split(new char[] {','}));
}

}

private void DoInsertData(string[] item)
{
string sql = "INSERT INTO tblPassages (column_num, row_num) VALUES (@p1, @p2)";

cmd.CommandText = sql;

SqlParameter p1 = new SqlParameter("@p1", item[0]);

SqlParameter p2 = new SqlParameter("@p2", item[1]);
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
p1.SqlDbType = SqlDbType.VarChar;
p2.SqlDbType = SqlDbType.VarChar;
cmd.Connection = cn;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
cmd.Connection = null;
}


while I wxecute this code at the line : cmd.ExecuteNonQuery(); a exception is raised as follws:

System.Data.SqlClient.SqlException was unhandled
Message="String or binary data would be truncated.\r\nThe statement has been terminated."
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=8152
Procedure=""
Server="localhost"
State=2
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at SeatLayout.Form1.DoInsertData(String[] item) in D:\Box Office\SeatLayout\SeatLayout\Form1.cs:line 179
at SeatLayout.Form1.button2_Click(Object sender, EventArgs e) in D:\Box Office\SeatLayout\SeatLayout\Form1.cs:line 161
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at SeatLayout.Program.Main() in D:\Box Office\SeatLayout\SeatLayout\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


Please help me.....
Thanks in advance..


Regards
Sangram
AnswerRe: Exception Pin
valerian.precop10-Jul-07 20:36
valerian.precop10-Jul-07 20:36 
GeneralRe: Exception Pin
sangramkp10-Jul-07 21:17
sangramkp10-Jul-07 21:17 
GeneralRe: Exception Pin
Brady Kelly10-Jul-07 21:40
Brady Kelly10-Jul-07 21:40 
GeneralRe: Exception Pin
Rhys Gravell10-Jul-07 22:33
professionalRhys Gravell10-Jul-07 22:33 
AnswerRe: Exception Pin
valerian.precop10-Jul-07 21:39
valerian.precop10-Jul-07 21:39 
GeneralRe: Exception Pin
mav.northwind11-Jul-07 8:52
mav.northwind11-Jul-07 8:52 
AnswerRe: Exception Pin
Rhys Gravell10-Jul-07 22:29
professionalRhys Gravell10-Jul-07 22:29 
Questionevent fire Pin
SwaSubhaVijju10-Jul-07 19:20
SwaSubhaVijju10-Jul-07 19:20 
AnswerRe: event fire Pin
_AK_10-Jul-07 19:37
_AK_10-Jul-07 19:37 
AnswerRe: event fire Pin
Vikram A Punathambekar10-Jul-07 19:43
Vikram A Punathambekar10-Jul-07 19:43 
GeneralRe: event fire Pin
SwaSubhaVijju10-Jul-07 19:54
SwaSubhaVijju10-Jul-07 19:54 
AnswerRe: event fire Pin
gauthee10-Jul-07 19:59
gauthee10-Jul-07 19:59 
AnswerRe: event fire Pin
gauthee10-Jul-07 20:04
gauthee10-Jul-07 20:04 
Questiondatagrid Pin
SwaSubhaVijju10-Jul-07 19:03
SwaSubhaVijju10-Jul-07 19:03 
AnswerRe: datagrid Pin
Sathesh Sakthivel10-Jul-07 19:18
Sathesh Sakthivel10-Jul-07 19:18 
GeneralRe: datagrid Pin
SwaSubhaVijju10-Jul-07 19:22
SwaSubhaVijju10-Jul-07 19:22 
GeneralRe: datagrid Pin
Sathesh Sakthivel10-Jul-07 19:26
Sathesh Sakthivel10-Jul-07 19:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.