|
hi all, i have one small question...
do we have ScaleTransform in winforms like that we are having WPF ?
i need to do some work regarding this? please help me
|
|
|
|
|
yes.
doesn't Google work where you are?
|
|
|
|
|
Hello guys,
I'm reading from a database using this called below:
private void GetAllMembers()
{
string query = @"SELECT * FROM [member_details] INNER JOIN club_details ON club_details.memberno = member_details.memberno WHERE [date_added] BETWEEN '" + date_from.SelectedValue.ToString() + "' AND '" + date_to.SelectedValue.ToString() + "'AND primsecconttype = '" + memb_type.SelectedValue.ToString() + "' AND [contracttype] = '" + class_type.SelectedValue.ToString() + "'";
try
{
conn.Close();
cmd = conn.CreateCommand();
cmd.CommandText = query;
conn.Open();
reader = cmd.ExecuteReader();
memb_names.Items.Clear();
while (reader.Read())
{
string firstnames = (string)reader["firstname"];
memb_names.Items.Add(firstnames);
}
if (!reader.Read())
{
error.Visible = true;
error.Text = "Sorry no mambers found in this range..";
}
}
catch (SqlException fff)
{
error.Visible = true;
error.Text = "Error occured: " + fff.Message;
}
}
The issue is that, when I read from a database and no record
is returned I would like to let the user know. it works when
I use an if() else statement but this will only return one
record if by chance the query returns something. A while loop
returns all the records, but I AM FAILING to find a way I can
let the user know if the query returns nothing after using a while loop.
Any help please on how I can let the user know if a while loop returns
nothing???
Thanks,
Mo
|
|
|
|
|
OK. First of all, look up parameterized queries, if you can't use stored procedures.
Second, I fail to realize what your problem is. Your while loop adds items to your collection, why not check the length of the collection after the while loop has run?
If it's 0 - obviously no records were returned.
And third: close your connection. Maybe add a finally statement to your try-catch ?
var question = (_2b || !(_2b));
|
|
|
|
|
Thanks man, you have made sound so simple.
I will try that
|
|
|
|
|
MorgSim wrote: Thanks man, you have made sound so simple.
I will try that
"It's all relative".
Seriously, good luck. I'm sure you'll get there.
var question = (_2b || !(_2b));
|
|
|
|
|
Hi.
i face a problem, record not update and no error show please check my coding and tell me where i do mistake
my coding is
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand();
conn.Open();
cmd.CommandText = "update contract set suppliername='" + dataGridView1.CurrentRow.Cells[1] + "',buyername='" + dataGridView1.CurrentRow.Cells[2] + "',contract_dt='" + dataGridView1.CurrentRow.Cells[3] + "',delivery='" + dataGridView1.CurrentRow.Cells[4] + "',pmode='" + dataGridView1.CurrentRow.Cells[5] + "',comm='" + dataGridView1.CurrentRow.Cells[6] + "',commper='" + dataGridView1.CurrentRow.Cells[7] + "' where contractid='" + dataGridView1.CurrentRow.Cells[0] + "'";
cmd.Connection = conn;
cmd.ExecuteNonQuery();
MessageBox.Show("Record Update..");
conn.Close();
}
|
|
|
|
|
If you are not sure what is going on, then enclose that code in a try...catch block and use
MessageBox.Show(ex.ToString()); to find out.
It may be that you have a try...catch block outside this method which is catching and discarding the error.
On a related note: change this to use parameterized queries, you are leaving yourself wide open to a SQL Injection attack. (Google for "Bobby Tables" to find out what that is)
P.S. When you give code fragments, always enclose them in <pre> </pre> blocks with the "code block" widget to preserve the formatting.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
The values you try to add to your ugly dynamic SQL are of type DataGridViewCell
So first of all, use dataGridView1.CurrentRow.Cells[x].Value to extract the values and as OriginalGriff already said, use parameterized queries.
It's easier, more readable, more efficient and NOT UGLY.
var question = (_2b || !(_2b));
|
|
|
|
|
hi i just want to display all empty fieldnames that are not filled up by the user
but my code has this errorer ' use of unassigned local variable 'messEmptyField' ; how can i fix this
<br />
private void btnSave_Click(object sender, EventArgs e)<br />
{<br />
string[] FieldName = { "Lastname", "Firstname", "Address", "Model", "Trouble Reported" };<br />
string messEmptyField;<br />
int i = 0;<br />
<br />
foreach (Control ctrl in groupBox1.Controls)<br />
{<br />
TextBox txt = ctrl as TextBox;<br />
<br />
if (txt.Text == string.Empty)<br />
{<br />
messEmptyField += FieldName[i];
}<br />
i++;<br />
}<br />
<br />
MessageBox.Show(messEmptyField + "please filled up all");<br />
dtDateLog.Focus();<br />
return;<br />
}<br />
<br />
<br />
<br />
<br />
|
|
|
|
|
This line:
string messEmptyField;
should probably be:
string messEmptyField = string.Empty;
|
|
|
|
|
hi
try this
string messEmptyField="";
|
|
|
|
|
uraghu wrote: string messEmptyField="";
Using string.Empty is the good practice.
|
|
|
|
|
You can try the following:
string messEmptyField = "";
--the choice is all yours!--
|
|
|
|
|
You can use String.Empty as the others say, or better still use StringBuilder:
private void btnSave_Click(object sender, EventArgs e)
{
string[] FieldName = { "Lastname", "Firstname", "Address", "Model", "Trouble Reported" };
StringBuilder messEmptyField = new StringBuilder();
int i = 0;
foreach (Control ctrl in groupBox1.Controls)
{
TextBox txt = ctrl as TextBox;
if (txt.Text == string.Empty)
{
messEmptyField.Append(FieldName[i]);
}
i++;
}
MessageBox.Show(messEmptyField.ToString() + "please filled up all");
dtDateLog.Focus();
return;
}
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
I am trying to create a simple text file and save it to C as:
File.Create(C:/Points.txt)
I am getting this error:
System.UnauthorizedAccessException was unhandled
Message="Access to the path 'C:\\Points.txt' is denied."
Source="mscorlib"
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, etc.
Can anyone tell me why? Its my computer and I am the sole user and administrator.
Thanks
|
|
|
|
|
Interesting, I tried and got the same error.
Then I tried with Notepad and I got the same error as well.
Seems to be one of those path were you need to be really the administrator (as in, if you said yes to an UAC prompt)
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I had absolutely no trouble doing this on XP, not even a warning. So I guess you're not using XP
|
|
|
|
|
|
Hy,
3 options:
0) Disable the UAC or play with it until W7 will let you copy on root(c:\)
without the UAC prompt.
1) Implement a UAC like button or something for this purpose
Here's an example on how to bypass the UAC
2) Use the application folder
I highly recommed nr 2)
modified on Tuesday, April 6, 2010 10:56 PM
|
|
|
|
|
Thanks
|
|
|
|
|
Vista doesn't allow writing to the root directory; get a better operating system (XP).
Better yet, store application data in the application data directory.
|
|
|
|
|
Trouble with storing in the application directory is then you have to have the user browse to where he stored the application so you can pick up the path. Better than random locations on C I suppose.
|
|
|
|
|
The application data directory.
|
|
|
|
|
Hello everyone,
I need to call a function that needs arguments from a COM object using the IDispatch interface. I have been able to call functions that does not need parameters and to get values from properties of the COM object using the Invoke function of the IDispatch interface. However, I am unable to call a function with parameter using the Invoke function of IDispatch. I believe it is because I don't set in the proper way the value "rgvarg" of the DISPPARAMS structure that must be passed to the invoke function to represent the arguments that must be passed to the object function. DISPPARAMS.rgvarg is expecting a IntPtr that represent an array of objects.
Does anyone have done this?
Here is a sample code of my program.
Type tSWApp = Type.GetTypeFromProgID("SldWorks.Application");
object swApp = Activator.CreateInstance(tSWApp);
IDispatch idisp = (IDispatch)swApp;
Guid guid = new Guid();
int[] nIds = new int[] { 0 };
nRetVal = idisp.GetIDsOfNames(ref guid, new string[] { "Visible" }, 1, 0, nIds);
DISPPARAMS dispParams = new DISPPARAMS();
dispParams.cArgs = 0;
dispParams.cNamedArgs = 0;
object pVarResult;
System.Runtime.InteropServices.ComTypes.EXCEPINFO excepInfo = new System.Runtime.InteropServices.ComTypes.EXCEPINFO();
nRetVal = idisp.Invoke(nIds[0], ref guid, 0, (ushort)System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYGET, ref dispParams, out pVarResult, ref excepInfo, null);
object[] oArgs = new object[]{ 10 };
nRetVal = idisp.GetIDsOfNames(ref guid, new string[] { "GetUserPreferenceIntegerValue" }, 1, 0, nIds);
dispParams.cArgs = 1;
--> dispParams.rgvarg = ???; <-- Here, I must provide a IntPtr object that represent the array "oArgs" defined above.
dispParams.cNamedArgs = 0;
dispParams.rgdispidNamedArgs = new object[] { };
nRetVal = idisp.Invoke(nIds[0], ref guid, 0, (ushort)System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_FUNC, ref dispParams, out pVarResult, ref excepInfo, null);
Thanks!
|
|
|
|
|