|
Hi,
I've got a query which looks similar to this: "...FROM xy WHERE ID=@Id AND NAME IN (@Names)". I want to pass multiple parameters for @Names, so that it would be like:
"...AND NAME IN ('Susi', 'Peter', 'Steven')"
Is this anyhow possible with the use of parameters? Is could form a qry like that in the code with building up the string, but I would prefer the way with parameters.
The problem is that when I setup @Names to be AnsiString or String (Varchar) then it builds something like this: N'Susi, Peter, Steven'. That's one long String so it searches in the DB like the following: "... NAME IN('Susi, Peter, Steven') - which of course, doesn't exist.
Any ideas? Impossible?
Thx, Shi
|
|
|
|
|
TheShihan wrote: I've got a query which looks similar to this: "...FROM xy WHERE ID=@Id AND NAME IN (@Names)". I want to pass multiple parameters for @Names, so that it would be like:
"...AND NAME IN ('Susi', 'Peter', 'Steven')"
Don't know exactly, try this
FROM xy WHERE ID=@Id AND NAME IN (@Name1,@Name2,@Name3) add parameters for all these.
|
|
|
|
|
the problem is, that you don't know in advance, how many parameters are passed. It's dynamic.
|
|
|
|
|
TheShihan wrote: I've got a query which looks similar to this: "...FROM xy WHERE ID=@Id AND NAME IN (@Names)".
I don't think you can do this.
One way you could do this without dynamically constructing a SQL statement to execute is to split your comma-separated list and load the items into a table variable. You can then JOIN your table xy to your table variable to find the records in this table where the name is in the list.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
TheShihan wrote: to pass multiple parameters for @Names
Something like this[^]
Once you have mastered the ability to turn yourself invisible at will, and to deflect bullets with your hair, you will be ready to come back here to the lounge and post programming questions.Only at this point will you be able to dodge the fireballs that are going to come your way. - Pete O'Hanlon
|
|
|
|
|
ho to add right-click to a "Console" object ?
thanks
|
|
|
|
|
You cant.
xacc.ideIronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
Why on Earth would you want something like that?
I will use Google before asking dumb questions
|
|
|
|
|
|
hi,
I have fetched two database tables "MTQABenchMarks" and "Users" in the datagridview. This is a windows application. Now I have to update the "MTQABenchMark" database after making changes to the datatable present in the application. When I run the code it is throwing an exception "Dynamic SQL generation is not supported against multiple base tables." How to solve this. the code is
public Form1()
{
InitializeComponent();
}
static SqlConnection Con = new SqlConnection("Data Source= 192.168.100.234; Initial Catalog=gishyd; User ID=sa; password=gis*2005");
SqlDataAdapter Da = new SqlDataAdapter("SELECT dbo.Users.UserID, dbo.MTQABenchMark.Id as EmpID, dbo.Users.FirstName + ' ' + dbo.Users.LastName AS Name, dbo.MTQABenchMark.NoofMinPerDay,dbo.MTQABenchMark.PerMonth FROM dbo.Users INNER JOIN dbo.MTQABenchMark ON dbo.Users.UserID = dbo.MTQABenchMark.EID ", Con);
DataSet Ds = new DataSet();
private void Form1_Load(object sender, EventArgs e)
{
Da.Fill(Ds, "MTQABenchMark");
dataGridView1.DataSource = Ds.Tables["MTQABenchMark"];
}
private void button2_Click(object sender, EventArgs e)
{
SqlCommandBuilder CmdBld = new SqlCommandBuilder(Da);
Da.InsertCommand = CmdBld.GetInsertCommand();
Da.Update(Ds, "MTQABenchMark");
MessageBox.Show(" Database is Updated");
}
}
}
Nitin Raj Bidkikar
|
|
|
|
|
Select query can be run against multiple tables, while Update query can be run only one table. In your application you select data from 2 tables, and store it in a dataset. When you try to update the database you use the same dataset. It's not possible, because the application tries to update 2 tables at the same time. You should do a separate update for each table, with values from your dataset.
Hope it helps.
I will use Google before asking dumb questions
|
|
|
|
|
how do you suggest to do that
Nitin Raj Bidkikar
|
|
|
|
|
Split the dataset into 2 datasets or datatables that contain fields from only one table, and then use these to update the database.
I will use Google before asking dumb questions
|
|
|
|
|
I won't write the code for you...try to do something and if you get stuck...post a question with your problem.
I will use Google before asking dumb questions
|
|
|
|
|
Hi,
I got a problem that I would like to return a generic object in a non-generic object, what can I do?
I searched a lot of page but it's talking about how to use or implement a generic class, but if I want to implement a normal class and return a generic object according parameter, what can I do?
e.g.
class DaoFactory
{
Dao<T, IdT> GetDao(Type t)
{
//something like this.
//how to implement?
}
}
Thanks
Jr. P
calendarw
|
|
|
|
|
How about this one?
/// <summary>
/// Convert an ArrayList from a derived type to the base type
/// </summary>
/// <typeparam name="S">Derived type</typeparam>
/// <typeparam name="D">Base type</typeparam>
/// <param name="list">The ArrayList</param>
/// <returns>An ArrayList containing elements converted to the base type</returns>
public static List<D> Transform<S, D>(List<S> list) where S : D
{
List<D> lst = new List<D>();
foreach (S element in list)
lst.Add(element);
return lst;
}
I will use Google before asking dumb questions
|
|
|
|
|
Thank you.
I changed to this:
public static List<D> Transform<D>(System.Collections.IList list)
{
List<D> lst = new List<D>();
foreach (D element in list)
lst.Add(element);
return lst;
}
Actually, I tried to search using google but I don't know what keyword should be used for this case.
|
|
|
|
|
How about [this]
Hope it helps.
I will use Google before asking dumb questions
|
|
|
|
|
Thank you for your information.
And I would like to implement something like this:
public interface IReadOnlyDao
{
object GetById(object id);
IList GetAll();
}
public interface IReadOnlyDao<T, IdT> : IReadOnlyDao
{
T GetById(IdT id);
IList<T, IdT> GetAll();
}
But when I implementing the GetAll(), I got a problem that two method are same name and same parameter, is it possible to implement? or I am required to use convert the list using previous discuss method.
Thank you very much.
|
|
|
|
|
I think it will be better to use the converter. My opinion
I will use Google before asking dumb questions
|
|
|
|
|
|
how to add support for "text drag and drop" for a console application in .NET ?
it has to accept dropped text on the console window.
thanks.
|
|
|
|
|
A drop target must be there enabled in the application for it to accept drag and drop requests. Isn't it?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
not sure how I do this for a "Console" object.
|
|
|
|
|