Friday, March 30, 2012

Modifing Data in SQL

Hello, and sorry for the vauge title.

Basically, I am building a web application where people can enter in raffles. So I set up a SQL DataBase, where I have a table for each raffel going on. In each, I have a UserName collum, and a ID collum, the ID being the key collum. On my page, I basically have a TextBox and a Button.


I know I add a SqlDataSorce to the page, and use a INSERT command, however I am not sure how to parse this in a way to make it so that when you type your UserName into the TextBox, and then click the submit button, it will create a row using the UserName.

Thanks for the help!

I'm assuming that your key column is an identity column, so we don't have to create a new key.

You have a seperate table for each raffle, and each one has its own username column? I suspect that you're better off with one table for all raffles, and a key field for the raffle that a row is for. That way you don't have to create a new table every time someone does a raffle.

Let's assume that the function GetTable() returns the name of the table for the raffle the user's signing up for.

source.InsertCommand = "Insert into " + GetTable() + "(UserName) Values(@.UserName)"

Then bind the data source to your textbox.

|||

Thanks, but I don't get the last part, "Then bind the data source to your textbox." Because if you do that, then it won't interact with the database.

And if you ment it the other way around, (Bind the textbox to the data source), I can't. You can't bind textboxes to datasources.

Help?

|||

I don't do much with SqlDataSources. If it were a straight SqlCommand, then inthe click event of your button, I'd have

cmd.Parameters["@.UserName"].value = txtUserName.Text;

cmd.ExecuteNonQuery();

|||

Sorry if this is really obvious, and I'm just stupid, but I can't figure out what to use for "cmd". I think you are refering to the SqlCommand, (Insert), but that doesn't work. (I've also tried InsertCommand).

Sorry that I can't get this.Stick out tongue

No comments:

Post a Comment