Showing posts with label box. Show all posts
Showing posts with label box. Show all posts

Monday, March 26, 2012

How to save contents of Text box to database?

Hi,

For some reason I can't use the edit, update or insert features on my remote shared server, so I am looking to create a web page that has text boxes on it, that I can enter data into, that will be saved into my database.

This is opposed to entering the data directly into the database itself. I want to be able to use a webpage, for simply adding new data, and saving it so that the new data updates and saves over the top of the old data.

What are the steps involved in doing this?

Any example code for just one text box would be appreciated, I could then extend it to suit my needs. Tia.

As I understand you want to get data in text box in you website and then update or insert to the database table. Here I wrote a very simple sample in C#:

protected void Button1_Click(object sender, EventArgs e)
{
string connectionString = @."Data Source=Confute\SQL2000;Initial Catalog=tempdb;Integrated Security=SSPI;";

using (SqlConnection connection = new SqlConnection(connectionString))
{
// Connect to the database then retrieve the schema information.


SqlCommand cmd = new SqlCommand("sp_UpdateMytable", connection);
connection.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@.id", txtBox_ID.Text);
cmd.Parameters.Add("@.name", txtBox_Name.Text);
int i = cmd.ExecuteNonQuery();

}

And the storedprocedure sp_UpdateMytable will update a table t1(id int, name varchar(30)) in this way:


create proc sp_UpdateMyTable @.id int,@.name varchar(30)
as
if exists (select * from t1 whereid=@.id)
update t1 setname=@.namewhere id= @.id
else insert into t1 select @.id,@.name
go

|||

Thanks Lori_Jay,

I actually resolved the issue and did switch the answered tag on this thread. I am sure your solution would work, however mine was a more simple issue, actually I will mention it here for other poor souls who struggle with the same issue I did.

Basically, I did not have a Primary Key set in my table of my database. Firstly, I was taught that although its a good idea to have a PK, it's not absolutely necessary. Because I had one table, with one column and one row, Idecided not to have one.

If you don't have one, then in Visual Studio 2005, you cannot access the Advanced SQL options, which are INSERT, UPDATE & DELETE, this seems to be a major fault if you ask me because there is ZERO error reporting and ZERO documentation about it.

I got lucky when I did a Google for it (after a week of endless suffering) to find one site in the entire world, written in Russian (which I had to translate very poorily), which stated that you need a PK. I quickly added a PK to my table and it worked instantly.

Perhaps the powers that be whom monitor these forums, can look into this and document it so that others are spared the same distress.

Regards.

How to run the snapshot agent using the -PublisherLogin ?

I am Merge replicating from MS SQL Server 2000 SP4 to a MS SQL Server 2000
SP3 box.
Get the following error while running the Merge Agent:
Error Message : The process could not log conflict information.
Error Details : The process could not log conflict information. (Source:
Merge Replication Provider (Agent); Error number: -2147200992)
Could not find stored procedure ''.
(Source: <publishing servername> (Data source); Error number: 2812)
On the Microsoft support website
http://support.microsoft.com/default...b;en-us;308743
it says this happens when 'If Merge Replication is configured so that the
Snapshot Agents connect to the Publisher by using a login that is defined as
a member of db_owner (and not a system administrator) in a database that is
merge published, if conflicts are detected during the Merge Process the Merge
Agent fails with this error message'
They offer a workaround which is :
To work around this behavior, run the Snapshot Agent with the
-PublisherLogin parameter and specify a login. For example, use the sa login,
which is a system administrator on the Publisher to generate a new snapshot.
After the snapshot completes, SQL Server creates the conflict stored
procedure. Then, you can rerun the Merge Agent so that SQL Server can log the
conflicts. Because you are not reinitializing the subscription, SQL Server
does not apply the new snapshot to the subscribers.
How do I run the Snapshot Agent with the -PublisherLogin parameter ?
On your publisher server there's a job which creates the snapshot. The
name of the job varies but you can recognize it by the category
REPL-Snapshot.
When you open the properties of the job, go to to Steps tab and edit
the "run agent" step by adding the parameter.
M

Friday, February 24, 2012

how to retrieve a password saved by SQL server

Hi,

I am able to connect to a SQL server and have checked the "remember my password" box in the connection diaglog window. Unfortunately, I forget what the password is, and now have to use it elsewhere. How can I get it? (I tried copy and paste, but it won't work).

Thanks,

Hi,

Unfortunatly I am beginer in this but it happens for me to have a corrupted master database and I couldn't login to SQL. The solution it was that I restore the master database using the command: rebuildm.exe from the SQL CD.

If I would have a problem like you, I would make a screen shots of all the settings which I have, I will detache the database I will stop the SQL service and I will restore the master database and I will put a new password and redo all the settings.

Good luck,

Diana

|||

Diana, thanks a lot for reply. I am still hoping there might a way to extract the password from my computer (since i have no trouble connecting to the server). Does anybody have any idea?

Thanks,

June

|||MSSQL stores not passwords but password hashes. There is no way to retrieve clear password from its hash: the hash operation is irreversible.