|
Create a query with parameters that have the same name as the fields, like:
"insert into aTable (Some, Other) values (@Some, @Other)"
Create a command object with the query, and add parameter objects for the parameters.
Do you have the data type for the fields?
---
b { font-weight: normal; }
|
|
|
|
|
public string[] GenInsertCmd(DataTable table)
{
string inscmd = "insert into " + table.TableName.Trim().ToLower() + " (";
foreach(DataColumn col in table.Columns)
{
inscmd += col.ColumnName + ",";
}
inscmd = inscmd.Substring(0,inscmd.Length - 1) + ") values (";
string[] sqlcmd = new string[table.Rows.Count];
int i = 0;
foreach(DataRow row in table.Rows)
{
sqlcmd[i] = "";
foreach(DataColumn col in table.Columns)
{
switch (col.DataType.Name.Trim().ToLower())
{
case "string":
try
{
sqlcmd[i] += "'" + ((string)row[col]).Trim().Replace("'","\"") + "',";
}
catch
{
sqlcmd[i] += "null,";
}
break;
case "datetime":
try
{
sqlcmd[i] += "'" + ((DateTime)row[col]).ToString("yyyy-MM-dd hh:mm:ss.sss") + "',";
}
catch
{
sqlcmd[i] += "null,";
}
break;
case "boolean":
try
{
sqlcmd[i] += ((bool)row[col] == true ? "1," : "0,");
}
catch
{
sqlcmd[i] += "null,";
}
break;
case "byte[]":
sqlcmd[i] += "null" + ",";
break;
default:
if (row[col].ToString().Trim() == "")
sqlcmd[i] += "null,";
else
sqlcmd[i] += row[col].ToString().Trim() + ",";
break;
}
}
sqlcmd[i] = inscmd + sqlcmd[i].Substring(0,sqlcmd[i].Length - 1) + ")";
i += 1;
}
return sqlcmd;
}
|
|
|
|
|
Ouch. Don't use a try statement to handle the null values, use an if statement instead. Exceptions should not be used for normal program flow.
---
b { font-weight: normal; }
|
|
|
|
|
i'm trying to make a picture box size itself, and zoom the image in it, when the mouse_move event is fired...the size part works....but it doesn't zoom.
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
System.Drawing.Size sz = new Size();
sz.Height=450;
sz.Width=600;
pictureBox1.Focus();
pictureBox1.Size = sz;
}
rzvme
|
|
|
|
|
Did you set the PictureBox.SizeMode property to PictureBoxSizeMode.Zoom ?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
yup...tried that 2.
could the problem be the fact that i have 8 picturebox controls...very close to each other(there is no space between them))?
rzvme
|
|
|
|
|
rzvme wrote: could the problem be the fact that i have 8 picturebox controls...very close to each other(there is no space between them))?
I don't think this is a problem. Even if the picture boxes overlap each other there should be no problem. Maybe you have to explicitely tell the picture box to redraw (Invalidate, Refresh, Update). Or there is some setting that prevents the image from getting zoomed (MaximumSize or something like this). Debug your app and check how the properties of your picture box change when your event handler is executed.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
10x for the tip. Now it works, but when the event is fired the picture is zoomed, and the picturebox size is modified , but the only part of the picture visible to me is the top left corner of the picture. What's wrong?
rzvme
|
|
|
|
|
how to pass variables through forms. I wish to make a a window form with a textbox.text from other form in my aplication
|
|
|
|
|
Passing values between forms[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hello
I was wondering : when I use System.Threading and use files, do I have a process switch or will another thread in the program get the remaining time share.
Clint
|
|
|
|
|
I'm not sure if I fully understood the question, but if you're using threads from System.Threading the time the threads are running are automatically scheduled and switched by the windows for you.
|
|
|
|
|
Also, if you're going to be writing a multi threaded app, be sure to make your data thread safe using syncronization objects, or one thread could overwrite your data while you're working with it in another thread.
|
|
|
|
|
Please can anyone help me to know where can i get a SFTP clint and server dll which can be integrated with my windows form C# application
Thanks and Regards
Pavan Joshi
|
|
|
|
|
how can i create a mobile application in C# using Mobile API?
|
|
|
|
|
hi,
i m having problem in reading values from database. something silly i m doing but can't figure it right now. Any help is welcome
public void getColumnNames(string col)<br />
{<br />
string constr = System.Configuration.ConfigurationManager.AppSettings["conskypak"];<br />
String cmdstr = "SELECT columnname FROM TableDescription where RecordCode=' " + col + " ' ";<br />
SqlConnection cn = new SqlConnection(constr);<br />
SqlCommand cmd = new SqlCommand(cmdstr,cn);<br />
SqlDataReader dr;<br />
cn.Open();<br />
dr = cmd.ExecuteReader();<br />
while (!dr.Read())<br />
{<br />
string name = "";<br />
name =(string)dr[0];<br />
}<br />
cn.Close();<br />
<br />
<br />
}
|
|
|
|
|
change this:
String cmdstr = "SELECT columnname FROM TableDescription where RecordCode=' " + col + " ' ";
to this :
String cmdstr = "SELECT columnname FROM TableDescription where RecordCode=' " + col.Trim() + " ' ";
it might be because of space which is with string.
|
|
|
|
|
thanx for all. it did not solved my problem. But u just directed me to think in the right direction. I just deleted all the spaces between after the recordcode and my problem was solved
|
|
|
|
|
try with this
while (dr.Read())
Where there is a will,there is a way.
|
|
|
|
|
It's not directly related to your problem, but you should make use of parameterized queries instead of building your queries by string concatenation. This way your code is protected against so called injection attacks and in my opinion they also make the code much more readable especially in cases where many parameters are used in one query.
Take a look at the following article here at CP: SQL Injection Attacks and Some Tips on How to Prevent Them[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
i have to return a string array from a function. I hv to retrieve the name to employees from emp table having certain code and return it to the calling function to be used for other purpose.
thanx in advance
|
|
|
|
|
public string[] getname()
{
DataSet ds = yourquery
string[] abc = new string[ds.Tables[0].Rows.Count];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
abc[i] = ds.Tables[0].Rows[i]["name"].ToString();
}
return abc;
}
|
|
|
|
|
Hi,
I have a really weird problem when deploying a couple of my C# libraries (using VS 2005). One of my libraries exposes events that are consumed by a VB6 application. Everything works great on my development computer.
When I deploy the C# assemplies on another computer (the assembles are registered properly with regasm /codebase) the VB6 application works fine EXCEPT that C# events are not triggered in the VB6 application.
So since the code works perfectly on the development computer, there must be something different about the way the DLL is registered. So do any of you know of a switch (or something) for regasm that needs to be specified in order for the events to be triggered?
Thanks.
|
|
|
|
|
I have written an application that limits how much time my teenage children are on the internet each day. It prompts them for a password. When the password box is up, they can go to the task manager (applications tab) and just kill my process. How can I protect may app from being killed that way?
Darryl Borden
Principal IT Analyst
dborden@eprod.com
|
|
|
|
|
I think you should create a a new user for ur children and give minimum rights to it. It would be better to make it a guest account. You can also apply policy using Microsoft Management Console and prevent them from opening Task Manager.
But it has proved that today's children are more clever than parents.
There is a saying in URDU which translates as "The children of today are so much clever as they are trying to evaluate the Night-Fly in the day."
Mujtaba
|
|
|
|