|
roiter wrote: use it as a string. So each byte is manipulateable by indexing
in C# the indexer (myString[x]) returns the 16-bit character at position x.
|
|
|
|
|
In .NET the characters are not bytes, they are unicode characters. A string is basically an array of char . A char is a 16 bit value, so you can cast it to a short or an int to get the character code.
Example:
foreach (char c in someString) {
int code = (int)c;
Console.Write(code.ToString("x4"));
Console.Write(" ");
}
---
single minded; short sighted; long gone;
|
|
|
|
|
Hello EveryBody,
I had two combo box (combo box1, combo box2)
I had populated the combox1 using dataset (having values in display member and value member)
I want to pupulate combo box2 on the selectedindexChangeEvent but
I am getting System.Data.DataRowView on comboBox1.selectedvalue.tostring();
I am unable to understand why it is returning this value.
And outside this event it is giving right value.
working on c# (windows application)
Regards,
rahul saini
|
|
|
|
|
It would be more helpful if you could put some code also...
Just call me Valy...
|
|
|
|
|
Hi Valy,
Here is the code for populating the combo box1
string sqlQuery = "select * from category ";
SqlConnection objConnection = new SqlConnection(objFunctions.strConn);
objConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(sqlQuery, objConnection);
DataSet ds = new DataSet();
adapter.Fill(ds);
DataTable objDataTable = ds.Tables[0];
cmb_category.DataSource = objDataTable;
cmb_category.DisplayMember = "categoryName";
cmb_category.ValueMember = "categoryId";
objConnection.Close();
AND on selectedIndexChangeEvent
I m populating combo box using comboBox1.selectedValue
but it is returning System.Data.DataRowView
Regards,
rahul saini
|
|
|
|
|
hi
instead of using combobox1.selectedvalue
you have to use
combobox1.selectedindex.tostring()
Nisar Inamdar.
|
|
|
|
|
Hi Nisar,
It is giving the index value but i want the selectedItemValue for populating
comboBox2 with help of the value i had to retrieve value from database
Regards,
rahul saini
|
|
|
|
|
Hi Rahul,
on combo1.selectedIndexEvent use query
" Select fieldName from tablname where fieldname="+combo1.Selectedindex.toString()";
Nisar Inamdar.
|
|
|
|
|
Yes I using the same query but
as on populating comboBox1 i get
category1 its value is 23
category2 its value is 32
but when on selecting category1 its index value is 0 and that is wat comboBox1.selectIndex is giving and i want its value that is 23.
Regards,
rahul saini
|
|
|
|
|
hi rahul,
Try combo1.SelectedItem.ToString();
It will be worked.
Nisar Inamdar.
|
|
|
|
|
I think I got it.
You must use ((DataRowView)comboBox1.SelectedItem).Row["categoryId"].ToString() instead of comboBox1.selectedValue
Just call me Valy...
|
|
|
|
|
Hi Valy ,
Thanks,
Its working fine.
Regards,
rahul saini
|
|
|
|
|
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
|
|
|
|
|
why do you use those two parameters @p1 and @p2 when you can simply do something like this:
string sql = "INSERT INTO tblPassages (column_num, row_num) VALUES ('" + item[0] + "','" + item[1] + "')";
I presume that column_num and row_num are string values in the database.
Usually you use parameters when you use a stored procedure to execute a query.
So you don't need these lines
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;
Tell me if it helped...
Just call me Valy...
|
|
|
|
|
Hi Valy,
I changed the code as you said but the exception is same.
Regards
Sangram
|
|
|
|
|
|
Please look at the problem when trying to help and please (as already has been said) don't give bad advice.
Looking at the message of the generated exception;
Message="String or binary data would be truncated.\r\nThe statement has been terminated."
...the cause is pretty obvious and if you're not aware of the cause, I imagine a Google search on this would tell you exactly what you need to know.
Rhys
"The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it"
They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance."
Terry Pratchett
|
|
|
|
|
SqlConnection conn = new SqlConnection(connectionString); //the sql connection
conn.Open();
string strQuery = "insert into Temp(ProductName,Cantity) values ('"+item[0]+"',cast ('"+item[1]+"' as numeric(5,0)))"; //the query
SqlCommand com1 = new SqlCommand(strQuery, conn); //the sql command
com1.ExecuteNonQuery();
conn.Close();
These is a sample of my code that works just fine. Are you sure the fields in the table are corect...
In my sample the table Temp has 2 fields, ProductName is nchar(50) and Cantity is numeric(5,0).
Be careful with the " ' " also (string values must be placed between ' in a query otherwise it doesn't work).
Just call me Valy...
|
|
|
|
|
As you've been told before, you should read (and understand) the problem and not give bad advice like building your SQL statements by string concatenation.
Hint: Google for "SQL injection".
The simple reason for the exception is (as the exception messages tells very clearly) that "String or binary data would be truncated." while trying to put some data into the database.
So obviously at least one of the values is longer than what the corresponding DB field can hold.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
It looks like you're trying to insert a string value into a field when the length of the string is greater than the length of the dB field.
For example, you're trying to do something akin to inserting the string 'This string is too long for my data field' into a VARCHAR(10) field.
Rhys
"The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it"
They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance."
Terry Pratchett
|
|
|
|
|
hi.
i am in interview of machine test...
help me please.
i need event in datagrid
when we clicking cell of datagrid using mouse then that particular cell color has to be chaged.
how can i do........
can anyone help me.......
thanking u..
|
|
|
|
|
SwaSubhaVijju wrote: i am in interview of machine test...
Are you giving any exam?
Apurva Kaushal
|
|
|
|
|
SwaSubhaVijju wrote: i am in interview of machine test...
You are aware this is cheating, right?
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
sorry i am not cheeting anyone...
they are providing me all facilities for search and do
i know i am a software engineer i wont cheet anyone...
|
|
|
|
|
Hi,
Go to your properties window of the datagrid, then go the events, there you would find the list of all datagrid events. You could select one as per your requirement.
Gautham
|
|
|
|