|
If anyone is familiar with Delphi and it's TADOQuery component, I would like to do something similar to the TADOQuery.Locate method.
If your not familiar with Delphi's TADOQuery.Locate, I want to be able to programatically select a newly added row. So the user can have a visual reference that a post was successful.
I read online sometime a ago that the TableAdapter.Select() method was the way to go but I can't seem to get it to work. Anyone?
I found this answer here
http://www.akadia.com/services/dotnet_find_methods.html
but it requires your tables to have primary keys and just my luck none of my tables have primary keys. By the way I didn't create these tables. How do I do the find without primary keys? I don't want to have to add them to all my Tables.
modified on Friday, April 16, 2010 4:53 PM
|
|
|
|
|
I am making a couple of assumptions here that may or may not be accurate. 1. Your datastore is a SQL database 2. You have no identity column (primary key is one type of identity column).
Without an identity column defined, SQL databases methods to return the last inserted record (@@identity or Scope_Identity()) will return NULL. Soooo you need another way to skin that cat.
One way, and there could be many options would be to make a clone of your current datatable before refreshing the data from the database and then compare the records to find the new one.
A way to do that would be something like:
datable1.merge(datatable2);
datatable3 = datatable2.GetChanges();
Then you could find the row or rows from datatable3 in your table and make that or them your current selection.
Hope this is helpful.
|
|
|
|
|
It's an SQL Server database and we do have identity columns but they are no primary key columns. I am able to use @@Identity and Scope_Identity() in the Delphi App and it works fine. I just need to figure out how to do it in C#.
|
|
|
|
|
This may work for you assuming you are dynamically generating your sql and submitting through an ADO query object.
Add a statement such as "Select Scope_Identity() From Table MyTable;" to the end of your dynamic sql. Then instead of submitting as ExecuteNonQuery(), run it as a regular query and the return value should be the row you added.
ymmv
|
|
|
|
|
I'm sorry I'm taking so long to reply to this thread, I'm a little busy. Ok so everything you said works but now how do I select the newly added row. I've tried several ways so far. e.g. this.bindingsource.contains(NewID), this.bindingsource.find(NewID). this.bindingsource.FindRows(NewID). But they never select any row except the very first row.
|
|
|
|
|
After searching long and hard I finally found a way to do it. Makes me wonder why I didn't think of this before.
for ( int i = 0; i < GridContact.Rows.Count; i++ )
{
if ((int)GridContact.Rows[i].Cells[1].Value == ID )
{
GridContact.ClearSelection();
GridContact.Rows[i].Selected = true;
}
}
|
|
|
|
|
After searching long and hard I finally found a way to do it. Makes me wonder why I didn't think of this before.
for ( int i = 0; i < GridContact.Rows.Count; i++ )
{
if ((int)GridContact.Rows[i].Cells[1].Value == ID )
{
GridContact.ClearSelection();
GridContact.Rows[i].Selected = true;
}
}
http://www.c-sharpcorner.com/Forums/Thread/84582/how-to-auto-select-a-newly-added-row-in-the-datagrid.aspx
|
|
|
|
|
static void ClearBoard(out char[,] board)
{
for (int Row = 0; Row < 3; Row++)
for (int Column = 0; Column < 3; Column++)
board[Column, Row] = ' ';
}
board will be passed in and will ALWAYS be of the form char[3,3];
When compiling, I get the error
"The out parameter 'board' must be assigned to before control leaves the current method".
Any idea why?
|
|
|
|
|
An out parameter is expected to be initialized in the called method, just as the error is telling you. If you are passing something in and want the same object returned, then use ref.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
With any array I don't think ref is required either.
|
|
|
|
|
True, i was speaking generically about the differences between the two
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
you don't need out nor ref, as all you are passing is an object, in this case an array of chars. objects get passed by reference, which means both parties (caller and callee) can access the object and modify it.
FYI: without out or ref the callee can not replace the object by a new object (actually, he can, but it will not affect the caller). But that is not what the name of the method implies, when it says ClearBoard it sounds like it is clearing an existing board.
If OTOH the method were intended to create a new and cleared board, I would call it CreateClearedBoard, and the proper way would be to make that the return object, dropping the void attribute.
|
|
|
|
|
performs a binary comparision. this memeber is equivalent to the visual basic constant vbBinaryCompare. what is the equivalent method in C#?
|
|
|
|
|
Seems like it does something comparable to StringComparison.Ordinal .. I'm not too sure though, I don't know VB.
|
|
|
|
|
I suggest you have a look at string.CompareOrdinal()
|
|
|
|
|
Please, I need some idea on how to secure a password string against keylogger spywares installed on a client host.
PLEASE, password input is via the KEYBOARD only.
thanks, ur suggestions will be appreciated.
|
|
|
|
|
You could register a new keyboard hook which doesn't call CallNextHookEx , that's a bit nasty though and it can break hotkeys and other programs (and keyloggers, but that's the point)
If you do this and a keylogger (re-)registers its hook, the keylogger will still work.
Also, it will only work against simple usermode keyloggers.
|
|
|
|
|
I have agridview i fill it from datatable but i want to add new emptyrow af first before filling
|
|
|
|
|
gridview.Rows.add("",""....);
OR
gridview.Rows.add(5);
EASY COME EASY GO
|
|
|
|
|
i tried this
gridview1.Rows.Add();
gridview1.DataSource = ds;
this exception
No row can be added to a DataGridView control that does not have columns. Columns must be added first.
|
|
|
|
|
this exception
No row can be added to a DataGridView control that does not have columns. Columns must be added first.
so what do you think the problem???
how many col in your database?
if 2
then
for example:
gridview1.columns.add("id","id");
gridview1.columns.add("name","name");
then try it
if it did not work try to add them row by row
EASY COME EASY GO
|
|
|
|
|
Thank u sanforjackass
thats help me alot.
|
|
|
|
|
EASY COME EASY GO
|
|
|
|
|
Hi,
I implemented this simple scenario containing 3 assemblies:
- TL (Transport Layer) assembly that contains only one class 'Class1':
public class Class1 : MarshalByRefObject { public int MyProperty { get; set; } }
and one interface:
public interface Interface1 { Class1 Get(int i); }
- BLL (Business Logic Layer) application that will act as a server in my remoting scenario. This assembly has reference to TL assembly and contains 2 files:
BLL Manager:
<br />
class BLLManager : Interface1 { public Class1 Get(int i) { return new Class1() { MyProperty = i - 1 }; } } <br />
And an xml file:
<?xml version="1.0" encoding="utf-8" ?><configuration> <system.runtime.remoting> <application> <channels> <channel ref = "tcp" port = "5001" /> </channels> <service> <wellknown mode = "SingleCall" type = "TL, Interface1" objectUri = "Uri1" /> </service> </application> </system.runtime.remoting></configuration>
The BLL assembly is a Windows Service. In the OnStart method I included the following code:
<br />
protected override void OnStart(string[] args) { RemotingConfiguration.Configure(@"C:\somefolder\BLL\bin\Debug\Config.xml", false); }
I installed this service and started it.
Third assembly is a simple Web application that acts as a .NET Remoting client here; it contains reference to TL as well. This assembly contains config file 'Web.config':
<?xml version="1.0"?>...
<system.runtime.remoting> <application> <client> <wellknown type = "TL.Interface1, Uri1" url="tcp://lsrv01:5001/BLL" /> < </client> <channels> <channel ref="tcp" port="0"/> </channels> </application> </system.runtime.remoting></configuration>
It also contains Default.aspx, which has the following C# code:
<br />
RemotingConfiguration.Configure(@"C:\/*some path*/\Web.config", false); <br />
Interface1 obj = (Interface1)Activator.GetObject(typeof(Interface1), "tcp://lsrv01:5001/BLL"); <br />
var i = obj.Get(5);
However I`m getting RemoteException in the last line. It say: "Server encountered an internal error. For more information, turn off customErrors in the server's .config file." In my web application I modified the web.config file accordingly:
<authentication mode="Windows"/> <customErrors mode="Off" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors>
But it didn't make any difference. Could you please help me to try to figure out what is wrong in my scenario?
Thank you very much for any useful help.
modified on Friday, April 16, 2010 11:58 AM
|
|
|
|
|
One of the reasons that .NET remoting is no longer used is because even the simplest remoting problem was complex to implement. It took me almost a year to become a remoting expert. Much of the remoting elements within the framework are also Obsolete.
I would suggest you deploy your service as a wcf service, then the rest is a very simple process. In your web application all you need to do is Add Web Service and you are running.
You can host the service in iis or bind it to whatever protocol you want. An advantage of WCF over Remoting is that you control the entire service config with an editor and attributes. You can build new wcf services and bind to them in a day without the headaches you are experiencing. As it is, once I started using WCF I completely let go of all memory of remoting. If you find you need to change protocols or bindings, it is a simple matter of changing attributes without changing any code.
Use WCF and forget about remoting ever existing.
|
|
|
|