|
He looked under the VB sofa and there it was.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
Hi everyone,
I have the following issue. I use the following code to retrieve all data row from an mssql database and during the process I update some values.
The issue I have is that it only updates the first row in the database. All other rows which should be updated (field: WEB_OBEZ,...) are NULL.
Does someone have an idea or can explain why it only updates the first row ?
Thank you very much!
private string FixOBez()
{
SqlConnection dbconn = new SqlConnection(this.sqlconn);
try
{
dbconn.Open();
SqlDataReader sqlreader = null;
SqlCommand mycmd = new SqlCommand("SELECT * FROM dbo.testdata", dbconn);
sqlreader = mycmd.ExecuteReader();
while (sqlreader.Read())
{
string obez = sqlreader["O_BEZ"].ToString();
string okuerzel = sqlreader["O_KURZ"].ToString();
string[] lines = GetNewOBez(obez);
SqlCommand sql2 = new SqlCommand("UPDATE dbo.testdata SET WEB_OBEZ1 = '" + lines[0] + "',WEB_OBEZ2 = '" + lines[1] + "',WEB_OBEZ3 = '" + lines[2] + "' WHERE O_KURZ = '" + okuerzel + "'",dbconn);
sql2.ExecuteNonQuery();
return "OK";
}
}
catch (Exception ex)
{
return ex.Message;
}
return "OK";
}
Bye,
ANeuby
|
|
|
|
|
Found the issue. The return was in the wrong line.
|
|
|
|
|
I have Gridview with AutoGenerateColumns to true(as I don't know how many columns will come). From database I am getting binary data. When I bind data table to gridview it displays checkbox with checked and unchecked. I need to display as 0 or 1. How can I do this?
|
|
|
|
|
You can do it in multiple ways like - converting that boolean property to a string property in gridview source object, make use of template in griview.
|
|
|
|
|
|
Change your query to return a string or integer instead of binary using convert() in TSQL (assuming SQL Server)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank u Holmes, working fine
|
|
|
|
|
Hi
I have used Visual Studio 2010 Express to develop a Windows application. I have published the program and the users install it from a shared location on a central computer. I have also done several updates that I have published without any problems. When the users run the program it first checks for updates and so far it has always picked up if there was an update and installed it.
The program is installed from a folder '\\MyServer\EPR\Installation\Install\' and the update location is '\\MyServer\EPR\Installation\Updates\'.
This morning I tried to roll out a new update. I copied the published files to the Updates folder as I have always done, but when I ran the application it checked for updates, but then it still ran the old version and did not install the new version.
The old version is 4.0.3.1 and the new version is 4.0.4.0.
Any ideas on what the problem can be?
At this stage my morning has been a complete waste and I feel very frustrated.
Regards.
Kobus
|
|
|
|
|
kbalias wrote: When the users run the program it first checks for updates
How does it do this?
kbalias wrote: Any ideas on what the problem can be?
Without seeing your code it is impossible to guess.
It's time for a new signature.
|
|
|
|
|
I need to create a billing software.At the sales page i need to create a listview and with in the listview i need to create multiple componets for typing sales details...I have gone through the web but i didnt get so help me...........
|
|
|
|
|
Winforms or webform - you do not say.
Listview does not accept components you need to use a datagridview (assuming winform)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If you working with windows forms you can check the XPTable article here in codeproject. It can fit you requirements.
If not you can create your own Listview, since default one is not editable.
|
|
|
|
|
Hi, fellow CodeProject members. I'm writing an application that contains a menu strip and a tool strip. The main application window is an MDI Container and on the left-hand side of the window is a splitter with a TreeView control. Depending on the TreeView's selected node I would like to enable/disable certain tool strip and menu strip items. What is the best way to go about doing so?
I currently do something like this:
private void mainTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
if (mainTreeView.SelectedNode == null) return;
TreeNode selectedNode = mainTreeView.SelectedNode;
switch (selectedNode.Level)
{
case 0:
break;
case 1:
if (selectedNode.Parent.Name == "RootNode1")
{
}
else if (selectedNode.Parent.Name == "RootNode2")
{
}
break;
}
}
}
There are currently eight items total for which I would like to toggle depending on the TreeView selection. I am only wanting to toggle the 'Enabled' state for the items. That's because, for example, root node 1 is selected so the user can only select "New Item...". Or if a child of root node 1 is selected then the user can choose "New Item...", "Edit Item..." or "Delete Item...". And root node 2 holds a different type of item so root node 1 items shouldn't be enabled in that case.
Is there a different way to go about this altogether? Do I have it all (or partially) incorrect? Or should I simply create a method for each case, such as "void ToggleRootNodeItems(int OneOrTwo)" and "void ToggleChildNodeItems(int ParentIsRootOneOrTwo)"?
I hope I explained my question fully. If you need more information I can provide you with whatever you need. Thanks much!
|
|
|
|
|
Using a switch or creating a different method for each node are valid ways to do it.
My preferred method in this case would be to use the Tag property of each TreeNode to store a List of ToolStripItem s that should be enabled when that node is selected. When the nodes are created (or in the form constructor, whichever is applicable) initialize the List s. Then in the selection change handler disable everything, then cycle through the list of ToolStripItem s for the selected node and re-enable each one.
Like this:
internal MyConstructor()
{
List<ToolStripItem> items = new List<ToolStripItem>();
items.Add(newItemButton);
items.Add(editButton);
rootNode1.Tag = items;
items = new List<ToolStripItem>();
items.Add(deleteItemButton);
items.Add(crashTheComputerButton);
rootNode2.Tag = items;
}
private void mainTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
if (mainTreeView.SelectedNode == null) return;
TreeNode selectedNode = mainTreeView.SelectedNode;
foreach(ToolStripItem item in )
{
item.Enabled = false;
}
List<ToolStripItem> applicableItems = selectedNode.Tag as List<ToolStripItem>;
if (applicableItems == null)
{
return;
}
foreach(ToolStripItem item in applicableItems)
{
item.Enabled = true;
}
}
|
|
|
|
|
Wow, thanks. LoL. I had no idea about the "Tag" property for TreeNode objects. I'll play with the example you gave and if I need anymore information I'll come back. Thanks a lot.
|
|
|
|
|
Alright, after reading your post and researching this a little bit, I finally implemented the code. I'll tell you, it looks 10x cleaner. LoL. Another thing I noticed is that when I ran the Code Metrics (VS2010) before, the "Maintainability Index" for that particular form was around 46 or 48 I believe. After changing to the method you described it went up to 55. I still have a few areas that I need to break into separate methods, which I believe may bring it up some more.
Thanks a lot for the help.
|
|
|
|
|
Glad to help
|
|
|
|
|
This seems like a stupidly simple request to me, but for some reason I cannot get it to work:
The hibernate manual says this:
String sql = "SELECT ID as {c.id}, NAME as {c.name}, " +<br />
"BIRTHDATE as {c.birthDate}, MOTHER_ID as {c.mother}, {mother.*} " +<br />
"FROM CAT_LOG c, CAT_LOG m WHERE {c.mother} = c.ID";<br />
List loggedCats = sess.createSQLQuery(sql)<br />
.addEntity("cat", Cat.class)<br />
.addEntity("mother", Cat.class).list()
Now, what I have is basically the same. I am return two of the same type per row. I am doing a select something like this:
SELECT {ctrl1.*}, {ctrl2.*} FROM tableA AS A<br />
LEFT JOIN tableB AS ctrl1 ON (A.controlID = ctrl1.controlID AND ctrl1.controlOptionType = ? AND ctrl1.controlOptionValue = ?)<br />
LEFT JOIN tableB AS ctrl2 ON (A.controlID = ctrl2.controlID AND ctrl2.controlOptionType = ? AND ctrl2.controlOptionValue = ?)
And then I addEntity("ctrl1", typeof(mycontrolclass) and addEntity("ctrl1", typeof(mycontrolclass)
Which seems exactly the same to me as their example. But I get this exception: "Could not execute query" and the inner exception is "Could not find specified column in results". If I copy the sql in the exception(to which it has added "AS ctrl1_1_3_3_" etc) it works fine.
Thanks.
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
It seems that I can't get this right... I'm using the following signature:
[DllImport("coredll.dll")]
private extern static uint RasGetEntryProperties(string lpszPhoneBook, string szEntry, ref RASENTRY lpbEntry,
ref int lpdwEntrySize, byte lpb, int lpdwSize);
Calling it with the following parameters:
RasGetEntryProperties(null, name, ref RasEntry, ref dwSize, 0, 128);
However, whenever this is called, an error pops up on my device telling me there has been a native exception, without much detail.
I've declared the RASENTRY struct as follows:
private struct RASENTRY
{
public int dwSize;
public int dwfOptions;
public int dwCountryID;
public int dwCountryCode;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxAreaCode + 1)]
public string szAreaCode;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxPhoneNumber + 1)]
public string szLocalPhoneNumber;
public int dwAlternatesOffset;
public RASIPADDR ipaddr;
public RASIPADDR ipaddrDns;
public RASIPADDR ipaddrDnsAlt;
public RASIPADDR ipaddrWins;
public RASIPADDR ipaddrWinsAlt;
public int dwFrameSize;
public int dwfNetProtocols;
public int dwFramingProtocol;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH + 1)]
public string szScript;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH + 1)]
public string szAutoDialDll;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH + 1)]
public string szAutoDialFunc;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceType + 1)]
public string szDeviceType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceName + 1)]
public string szDeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxPadType + 1)]
public string szX25PadType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxX25Address + 1)]
public string szX25Address;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxFacilities + 1)]
public string szX25Facilities;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxUserData + 1)]
public string szX25UserData;
public int dwChannels;
public int dwReserved1;
public int dwReserved2;
public int dwCustomAuthKey;
}
Any help would be appreciated, thanks!
-Brandon
|
|
|
|
|
Hi guys. I am having a problem with the above. I am trying to update the changes made to the gridview back to the database but for some reason I get a "Data Type mismatch in criteria expression" OleDbException. I have tried a number of updates but nothing seems to work. Below is the code I am using. I have delete section which works fine. Just the Edit portion that doesn't work. Can somebody please advise what I am missing here?
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int currentRow = int.Parse(e.RowIndex.ToString());
int rowint = 0;
string sql = "SELECT TimesheetDetailID, EmployeeID, TSProjectCodeID, TimeSheetDate, HoursWorked, TaskCode, Notes from tblTimesheetDetails WHERE TimesheetDetailID ='" + rowint + "'";
string empID = dataGridView1[1, currentRow].Value.ToString();
string projcode = dataGridView1[2, currentRow].Value.ToString();
string timedate = Convert.ToString(dataGridView1[3, currentRow].Value.ToString());
double hrs = Convert.ToDouble(string.Format("{0:f}", (dataGridView1[4, currentRow].Value.ToString())));
string taskcode = dataGridView1[5, currentRow].Value.ToString();
string notes = dataGridView1[6, currentRow].Value.ToString();
OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);
OleDbCommandBuilder cmb = new OleDbCommandBuilder(da);
da.Fill(dataTable);
string updateString = "Update tblTimesheetDetails SET EmployeeID ='" + empID + "', TimesheetID ='" + "" + "', TSProjectID ='" + projcode + "', TimeSheetDate ='" + timedate + "', HoursWorked ='" + hrs + "',TaskCode ='" + taskcode + "', Notes ='" + notes + "' WHERE TimesheetDetailID ='" + rowint + "'";
try
{
conn.Open();
string timesheetString = dataGridView1[0, currentRow].Value.ToString();
rowint = int.Parse(timesheetString);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
if (dataGridView1.Columns[e.ColumnIndex] == deleteButton && currentRow >= 0)
{
string queryDeleteString = "DELETE FROM tblTimesheetDetails where TimesheetDetailID = " + rowint + "";
OleDbCommand sqlDelete = new OleDbCommand();
sqlDelete.CommandText = queryDeleteString;
sqlDelete.Connection = conn;
sqlDelete.ExecuteNonQuery();
}
else if (dataGridView1.Columns[e.ColumnIndex] == editButton && currentRow >= 0)
{
try
{
if (dataTable.Rows.Count != 0)
{
dataTable.Rows[rowint]["EmployeeID"] = empID;
dataTable.Rows[rowint]["TimesheetID"] = 0;
dataTable.Rows[rowint]["TSProjectCodeID"] = projcode;
dataTable.Rows[rowint]["TaskCode"] = taskcode;
dataTable.Rows[rowint]["TimeSheetDate"] = timedate;
dataTable.Rows[rowint]["HoursWorked"] = hrs;
dataTable.Rows[rowint]["Notes"] = notes;
dataTable.AcceptChanges();
da.Update(dataTable);
}
}
catch (OleDbException exx)
{
MessageBox.Show(exx.Message.ToString());
}
}
conn.Close();
GetDataView();
}
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Do your table in the database have PK ?
I know sounds a bit Odd , but I was facing some problems in OleDB AcceptChanges() things ,
And solved by Adding PK to Mt Table in the database
thanks
I know nothing , I know nothing ...
|
|
|
|
|
Hi.
Yes, it does have a primary key. I am using the primary key to get the exact record in the cdatabase to update.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
You are passing all your criteria as strings, I suspect the date format is incompatible with the database.
Set a break point on conn.open() and inspect the string, try and execute the string in SSMS.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi Mycroft. Sorry for taking this long to reply. I have actualy set the DateColumn in the DB to a string column and I am passing a string. I have now tried numerous things and it just won't work. I have now decided to abandon the save changes from the datagrid and just to delete the row and the users can retype. I know it is not the best thing to do but if I can't et it working then I am stuck with doing that.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|