|
|
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
|
|
|
|
|
|
hi.........
how to get event in datagrid(when i press in cell of datagrid it should display alert message)
help me please......
|
|
|
|
|
Don't Cross post in Multiple Forums.
Regards,
Satips.
Don't walk in front of me, I may not follow;
Don't walk behind me, I may not lead;
Walk beside me, and just be my friend. - Albert Camus
|
|
|
|
|
i didnt get u what do u mean
|
|
|
|
|
You have posted the same question in the Asp.Net forum and also here .
Hope now you got it what i said.
Regards,
Satips.
Don't walk in front of me, I may not follow;
Don't walk behind me, I may not lead;
Walk beside me, and just be my friend. - Albert Camus
|
|
|
|
|
Crikey! He's posting the same question in the same forum, just phrasing it different!
What a bastard!!
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
You're going to have to dive into javascript to display an alert message.
Basically you can handle the ItemDataBound event, find the control you want to display the message for using FindControl, and do yourcontrol.Attributes.Add("onclick", "javascript: alert('whatever you want to say');")
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
thanks....
but i didnt get u if possible clear once again
|
|
|
|
|
in my C# program,i input "at" in a textBox,then the program send "at" to serialport,but when i click receive button,the message I receive from serial port is the same as I input,namely "at",not "ok",why?who can answer my question?How I solve this problem and get the right response "ok" from serial port?
next is my code:
public partial class Form1 : Form
{
private SerialPort sp = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
sp = new SerialPort("COM1");
sp.ReadTimeout = 5000;
sp.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
sp.Write(textBox1.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
/*string text=null;
char[] buffer = new char[10];
sp.Read(buffer,0,6);
for (int i = 0; i < buffer.Length; i++)
{
text += buffer[i];
}
textBox2.Text = text;*/
/*string text = null;
char t = (char)sp.ReadChar();
text+=t.ToString();
while (true)
{
t = (char)sp.ReadChar();
if (t == '\0') break;
else text += t.ToString();
}
textBox2.Text = text;*/
string text = null;
byte[] t = new byte[20];
char[] c = new char[20];
sp.Read(t, 0, t.Length);
sp.Read(t, 0, t.Length);
c = Encoding.ASCII.GetChars(t);
int i;
for (i = 0; i < c.Length; i++)
{
if (c[i] == 'O' || c[i] == 'K')
text += c[i].ToString();
}
textBox2.Text = text;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
|
|
|
|
|
Hi All
Any one know how to retrieve outlook appointment using MAPI and C#
gihan koli
|
|
|
|
|
Get it[^]
Regards,
Satips.
Don't walk in front of me, I may not follow;
Don't walk behind me, I may not lead;
Walk beside me, and just be my friend. - Albert Camus
|
|
|
|
|
I have a enum with string values.I want to store all this in a string array.
And want to check with a parameter of a function with the string array.
can any body has the code in c#?
|
|
|
|
|
Did you read my reponse to your earlier post?
If you did, but didn't like it, try:
System.Enum.GetNames ( typeof(YourEnumTYpe) )
|
|
|
|
|
You waited all of two hours to post your question again?
saymajum wrote: I have a enum with string values.
What on earth does that mean? Enums can only have int (and related types) values.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
I have just started writing a vector graphics program with C#. I want to use the Graphics object's ScaleTransform to control zooming. I haven't got to that coding stage yet but I'm wondering if anybody knows how you would enforce bounds when the graphics are scaled. For example, while the mouse is dragging a shape, I want the location change to be canceled if the object would have been dragged out of the drawing bounds.
may your code be error free
|
|
|
|