|
On click of a button how can i have data from one table into another in same database?
Actually i m making a login form,it has checked the data from a table for login from login table.
Now,i want some data from login table send to another table when user logs in.
Thank you for the response.
Nekshan.
|
|
|
|
|
If the two databases are on the same server then it is quite easy
You can fully qualify table names if you need to
[server].[database].[owner].[table]
[owner] if it is dbo can be omitted.
[server] can be omitted if both items are on the same server.
INSERT INTO destination_database..login
SELECT * FROM source_database..login
If the tables are on different servers then it becomes more complicated as you have to link the servers together first.
|
|
|
|
|
|
What is going wrong ? Does your connection fail ? What error do you get ?
I assume this code is not involved in the login process ? I also assume you haven't really called your button 'button1' ???
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
yes it's coming. thank u
|
|
|
|
|
Nekshan,
r u trying to insert values directly thrugh a query or a stored procedure??
Gautham
|
|
|
|
|
i m inserting data via query.
|
|
|
|
|
y cant u just give insert........values(textbox1.text.tostring, textbox2.text.tostring) instead of all the parameters!!!!
Gautham
|
|
|
|
|
Because parameterised queries provide some protection against SQL injection attacks.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
gauthee wrote: y cant u just give insert........values(textbox1.text.tostring, textbox2.text.tostring) instead of all the parameters!!!!
That would introduce vulnerabilities into the application. You really MUST read SQL Injection Attacks and Tips on How to Prevent Them[^] before giving out any more advice like this.
Also, myTextBox.Text returns a string already. So there is zero need to append ToString() on that.
|
|
|
|
|
He's plainly using SQL directly, you can see it there.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Other than the obvious security issue of storing a password in plain text I don't see anything wrong with this. What error are you getting?
|
|
|
|
|
*grin* I asked that, a half hour ago....
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Do NOT delete your query because it makes it very difficult for those with a possibly similar problem to find out the answer!!!
|
|
|
|
|
hi
I read msdn about collection and I understand
that when I want to make a collection of int,string etc.
I can use arryList but if I use objects I need to use collectionBase
the questions are:
1. why?
2. before I knew this fact i used arraylist to collect Labels Points
and I didn't have any problem during running the application.
so it seems that I can use arraylist for objects...
thanks
shaul
|
|
|
|
|
yes arraylist can have objects.
Gautham
|
|
|
|
|
groundzero111 wrote: if I use objects I need to use collectionBase
Where did you get that? As you noticed yourself this statement is wrong. One could say that you should use a custom collection derived from Collectionbase , because that custom collection can be made type-safe i.e. you can only add instances of a certain type and also only get instances of this type. In .NET Framework 2.0 you can use the generic List type, that is similar to the ArrayList with the advance of type-safety.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
You're using C# 2003.
An ArrayList contains a collection of objects. That's all it can contain. In C#2005, generics mean you can specify the type of objects that go into a collection. In C# 2003, EVERY collection contains objects, and that's all.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
thanx graus.
i have checked login,now i want loginid n password which user enters in textboxes into another database.
i m a student of computer science doing project work.
i m trying this code, but no effect :
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=PROGRAMER;Initial Catalog=statusutility;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = "INSERT INTO login(userid,password) VALUES (@pUsername,@pPswd)";
SqlParameter p1 = new SqlParameter("@pUsername", SqlDbType.VarChar, 50);
p1.Value = textBox1.Text;
cmd.Parameters.Add(p1);
SqlParameter p2 = new SqlParameter("@pPswd", SqlDbType.VarChar, 50);
p2.Value = textBox2.Text;
cmd.Parameters.Add(p2);
con.Close();
}
can u plz help on it?
Thank You.
Nekshan.
|
|
|
|
|
This code cannot have any effect, because you never execute the query. Insert cmd.ExecuteNonQuery(); before you close the connection.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Not often I see my name in a header...
If you want to get someone's attention, post again in the thread where you're talking to them. That way, I would have got an email.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi, any idea on why VS2005/C# always runs a project file when I try to run an existing solution file?
Say... I double clicks on a solution file. But when the VS2005 runs, the root in the Solution explorer appears to be its project file. Please help.
Thank you very much.
KiT
-- Never wait for a chance to come, Believe in your own potential and go get it! --
|
|
|
|
|
Sorry... I got it. The option to show the solution file is not checked -_-"
KiT
-- Never wait for a chance to come, Believe in your own potential and go get it! --
|
|
|
|
|
Hello dear gurus,
I'd like to know how I can detect in C# if the default instance of MS SQL Server is installed???
Is there a way to do that???
Can someone show me a code snipet or something please?
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
The default instance on a machine can be reached by connecting to localhost. So, you can try to connect and see what happens. But, if it's no running and not set to autostart, this will fail.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|