Saving to a Database

RPBLEA

Active member
Joined
Apr 26, 2005
Messages
36
Programming Experience
1-3
I kno wyou can use DataREaderAdapter Which I have been to read data, now what's the deal with Saving Data?
txtnotes.Text = reader.GetString(12)

Can you use the dataReader to save data also?
 
You should use a (OleDb/Sql)Command with an explicit CommandString or (OleDb/Sql)DataAdapter with a parameterised command and your data in a DataTable. The DataReader is, as the name suggests, only for reading data. If you need to read, manipulate then write data, it is probably better to use a DataAdapter for reading and writing.
 
RPBLEA said:
I kno wyou can use DataREaderAdapter Which I have been to read data, now what's the deal with Saving Data?
txtnotes.Text = reader.GetString(12)

Can you use the dataReader to save data also?

As jmcilhinney told you ... you can't savedata through datareader ... btw, let us know what you need to do in your projects and we will tell you
how you can do the job ...
Cheers ;)
 
I created a Stored Procedure to save data, and wrote the comand in aspx here is some code so people can look at it, Maybe you could improve upon it. It works though

whathappened = "Data was Saved"

Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("strDBConn"))

Try

conn.Open()

Dim cmd As New SqlCommand("saveorderkey", conn)

cmd.CommandType = CommandType.StoredProcedure

Dim cmd2 As New SqlCommand("log", conn)

cmd2.CommandType = CommandType.StoredProcedure

cmd2.Parameters.Add("@orderkey", txtorderkey.Text)

cmd2.Parameters.Add("@date", myDate)

cmd2.Parameters.Add("@time", myTime)

cmd2.Parameters.Add("@whathappened", whathappened)

cmd.Parameters.Add("@orderkey", txtorderkey.Text)

cmd.Parameters.Add("@building", txtbuilding2.Text)

cmd.Parameters.Add("@prefix", txtprefix.Text)

cmd.Parameters.Add("@cablepair", txtcablepair.Text)

cmd.Parameters.Add("@room", txtroom2.Text)

cmd.Parameters.Add("@panel", txtpanel.Text)

cmd.Parameters.Add("@ext", txtextension.Text)

cmd.Parameters.Add("@vgname", txtvgname.Text)

cmd.Parameters.Add("@port", txtport.Text)

cmd.Parameters.Add("@descr", txtdescription.Text)

cmd.Parameters.Add("@location", txtlocation.Text)

cmd.Parameters.Add("@jackdesi", txtjackdesi.Text)

cmd.Parameters.Add("@notes", txtnotes.Text)

cmd.Parameters.Add("@updated", txtupdated.Text)

cmd2.ExecuteNonQuery()

cmd.ExecuteNonQuery()

Catch ex As Exception

lblerr.Text = ex.Message

End Try

conn.Close()

End Sub

Stored procedure

CREATE PROCEDURE dbo.saveorderkey

@orderkey as int,
@building as varchar(25),
@room as varchar(25),
@panel as varchar(25),
@prefix as int,
@ext as varchar(4),
@cablepair as int,
@vgname as varchar(25),
@port as varchar(4),
@descr as varchar(50),
@location as varchar(25),
@jackdesi as varchar(25),
@notes as varchar(25),
@updated as varchar(25)

AS
insert into pairs(building, room, panel, prefix, ext, cablepair, vgname, port, descr, location, jackdesi, notes, updated)
Values (@building, @room, @panel, @prefix, @ext, @cablepair, @vgname, @port, @descr, @location, @jackdesi, @notes, @updated)
GO

 
Back
Top