|
Nader Elshehabi wrote: I'd be extremely surprised if that's what he was asking about?!! I had all sorts of guesses jumping in my mind of what really he was asking about. A guy who makes an SqlConnection didn't know how to convert a string to Int32?!!
I am not sure if you were talking of my message, but what I meant was. I have a datatable, already filled with information from the database. Now I need to use some of the data in that datatable, bind to a variable I can use throughout my application. I am building the app as a windows app.
The problem is, I have a MemberID(it's unique and primary key), that I need to use to get the member's language and name from the datatable. So I wanted to do something like
SELECT MemberID, MemberLanguage, MemberName FROM "mytable" where MemberID = strCurrentMemberID<br />
'mytable = the datatable
I dont know how to do this select from a datatable.
|
|
|
|
|
playout wrote: SELECT MemberID, MemberLanguage, MemberName FROM "mytable" where MemberID = strCurrentMemberID
'mytable = the datatable
That should do it
only two letters away from being an asset
|
|
|
|
|
Thanks, this might be helpful, only problem is, I dont know what row the value is in, so how can I search via row?
EG: The member details for the current row can be in row 5 or 68 for that matter, the only reference I have, is an employee number.
|
|
|
|
|
Given your scenario and my understanding of it, if you have more that one record returned then you have something wrong in your database.
only two letters away from being an asset
|
|
|
|
|
Please help! How can i access metod UpdateRows from another thread in this code?
Thanks.
using ...
namespace pddServer
{
public partial class Form1 : Form
{
public class ThreadedTcpServer
{
public void StartServer()
{
ConnectionThread newconnection = new ConnectionThread();
Thread newthread = new Thread(new ThreadStart(newconnection.HadnleConnection));
newthread.Start();
}
class ConnectionThread
{
public void HadnleConnection()
{
connections++;
//
// How can i call method UpdateRows from this place?
//
connections--;
}
}
}
private Thread ServerThread;
public Form1()
{
InitializeComponent();
ThreadedTcpServer Server = new ThreadedTcpServer();
ServerThread = new Thread(new ThreadStart(Server.StartServer));
ServerThread.Start();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ServerThread.Abort();
}
public void UpdateRows()
{
dataGridView1.Rows.Add();
}
}
}
|
|
|
|
|
Hello
Your multithreading module is not right IMO. Your thread must be an object in your From class, not in a separate class. Then it should know about the UpdateRows method's existence and call it using this.Invoke() .
Regards
|
|
|
|
|
Ok, I created a sql server database connection object for all to use if you're interested however I'm posting this on here with the hopes that people try to make improvements upon it and can share their changes with me. I've only been coding in C# for a little while now so I'm hoping for some advice on where I can make improvements.
Currently, it's only compatible with SQL Server & requires a stored procedure and it then reads a connection string stored in either the web.config or app.config file.
It can return data as a datatable or dataset or return nothing at all. Each method can accept up to 10 arguments to be passed into a stored procedure. If a user needs to declare more than 10 arguments, they must pass them in as an array.
So for those who don't know, a sample web.config file would be setup like this (although I recomend encrypting your config file if you use this on a server):
------------------------------------------------------------------
<configuration>
<appSettings/>
<connectionStrings>
<add name="SqlServerConnection"
connectionString="Data Source = yourDataSource;Initial Catalog = dbName;User Id =yourUserId;Password = yourPWord;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
-------------------------------------------------------------------
You can then create an instance of the DBConn object like the following:
----------------------------------------------------------------------
DBConn dbConnection = new DBConn("SqlServerConnection");
DataTable dtTable = dbConnection.PopulateDataTable("storedProcName", argument1);
----------------------------------------------------------------------
The file can be located at http://www.jennyperl.com/stuff/DBConn.zip
I'd greatly appreciate any advice/additions that can be made to this to help improve upon it. If you simply wish to use it as is and make no improvements, I hope it helps make your coding a little easier.
If you wish to contact me personally, you can email me at goalie35_33@yahoo.com.
Thanks.
-Goalie35
|
|
|
|
|
Goalie35 wrote: although I recomend encrypting your config file if you use this on a server
I strongly recommend using Windows Authentication to access your SQL Server so you don't have to store usernames and passwords in plaintext files.
Goalie35 wrote: Each method can accept up to 10 arguments to be passed into a stored procedure. If a user needs to declare more than 10 arguments, they must pass them in as an array.
Why not just use the params keyword then you won't have to have this limit. You can pass in as many as you like - Internally, within the method, you would still treat them as an array, but you wouldn't need to do that to call the method.
|
|
|
|
|
Goalie35 wrote: I'd greatly appreciate any advice/additions that can be made to this to help improve upon it. If you simply wish to use it as is and make no improvements, I hope it helps make your coding a little easier.
Have a look at the Data Access Application Block[^] in the Enterprise library.
|
|
|
|
|
Does anybody know if it is possible to write a program that will force the taskbar buttons associated with a certain program (a different one) to group? The problem I have is that a program written in LabVIEW by an outside contractor insists of having two taskbar buttons although one is basically a dummy for the LabVIEW runtime engine. The contractor says that there is no way to fix this from LabVIEW. I was wondering if it would be possible to write a small C# program to act as a loader for the LabVIEW program, force it's icons to group and then quit.
I found this article as a start, but it doesn't suggest a way to force buttons to group.
Thanks
|
|
|
|
|
Not sure if it'd work but how about using the C# "loader" program to have the ShowInTaskbar property of the main form set to false? I don't think this will work because if you simply execute the program (I.e. you can't link into it) then it will display it's icon.
There may be an API for this but as I hate WinXPs guts I have no idea on how to do this
|
|
|
|
|
Ed.Poore wrote: Not sure if it'd work but how about using the C# "loader" program to have the ShowInTaskbar property of the main form set to false?
Interesting, I didn't think of that. I'll have to give it a try and see what happens. Cheers.
|
|
|
|
|
Depends on how you load the program, I'm pretty sure if you just the shell to execute it then it won't work.
|
|
|
|
|
Ed.Poore wrote: I'm pretty sure if you just the shell to execute it then it won't work.
Yes, I am just using the shell to execute. From the Process class I can get the handle of the main window, but now I need to figure out if there is a way to use that to stop it from displaying a taskbar button.
|
|
|
|
|
|
Okay, I think I found a way to stamp out one of the toolbar buttons, so that will do for me. I had to import functions from user32.dll and use SetWindowLong with the WS_EX_TOOLWINDOW extended window style. That works fine so long as I hide the window (with ShowWindow and SW_HIDE) first and then show it again afterwards.
I'd tried using ITaskbarList to remove the taskbar button but that only worked until you clicked back on the remaining button and it recreated the missing button.
|
|
|
|
|
Good to see that it's beginning to come together.
|
|
|
|
|
hi,
how do i make my search go over my entire table, i can do it on one colmn:
db1DataSet.Tabel1.DefaultView.RowFilter = " column1 LIKE '%" + txt_sort.Text + "%' ";
dataGridView1.DataSource = db1DataSet.Tabel1.DefaultView;
can somebody help?
thx
|
|
|
|
|
faladrim wrote: how do i make my search go over my entire table
What do you mean? A search will go over your entire table (i.e. every row in the table matching the row filter). Do you mean how do you filter multiple columns? In that case you can just AND (or OR) your filters together:
MyDataTable.DefaultView.RowFilter = "column1 LIKE '%" + myCol1String + "%' AND column2 LIKE '%" + myCol2String + "%'";
|
|
|
|
|
what if i have 100 columns??
|
|
|
|
|
faladrim wrote: what if i have 100 columns??
Then it is likely that your database needs redesigning.
Disclaimer:
I understand that there are cases where tables require 100+ columns. But, from what I've seen, most tables of this size should in fact be broken up into smaller tables with one to one relationships.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
even 10 i find alot to write the query over and over for every colmn
i need something were i could say:
allcolmns like'%"+textbox.text"%'";
or is there no sutch thing?
|
|
|
|
|
i am trying to figger something out to recreate the query
for (colnr =1; colnr =colamount;colnr++)
{
string colname= dataset.table.colmns[colnr].tostring();
}
by this i get all the names of the colmns wright?
so if i could get this in the query, ill try it for one column:
string colname = dataset.table.colmns[1].tostring(); // get name of col 1
db1DataSet.Tabel1.DefaultView.RowFilter = colname+" LIKE '%" + txt_sort.Text + "%' ";
dataGridView1.DataSource = db1DataSet.Tabel1.DefaultView;
this should do the same as entering the real name of the column just befor" LIKE"
but here i get an error...
|
|
|
|
|
int colnr;
int colamount = db1DataSet.Tables[0].Columns.Count;
string cFilter = "";
for (colnr = 0; colnr < colamount; colnr++)
{
cFilter = cFilter + (cFilter.Length > 0 ? " OR [" : "[") + db1DataSet.Tables[0].Columns[colnr].ColumnName + "] LIKE '%" + txt_sort.Text + "%' ";
}
db1DataSet.Tables[0].DefaultView.RowFilter = cFilter;
dataGridView1.DataSource = db1DataSet.Tables[0].DefaultView;
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
thxxx
im sure it will work, but i most have made an mistake somewere cause i get this error:
System.Data.EvaluateException was unhandled
Cannot perform 'Like' operation on System.Int32 and System.String."
this only happens on a colmn named numbers, in acces i specifided it as text, but i wrote a function to make sure it were numbers.
have you ever come across anything like this? its probebly a stupid mistake
anyway thx for the help
grz
|
|
|
|