Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Kako upisati dataset u tabelu

[es] :: MS SQL :: Kako upisati dataset u tabelu

[ Pregleda: 1678 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

sparc
Sladjan Parc

Član broj: 65760
Poruke: 134
93.86.111.*



Profil

icon Kako upisati dataset u tabelu11.03.2009. u 18:29 - pre 152 meseci
Pomocu web servisa uspeo sam da dobijem "napunim" odredjen dataset koji ima odredjene podatke
sdrzane u redovima i kolonama. Kako da od tog dataset-a napunim tabelu koja nema veze sa
ovim datasetom, odnosno ima svoje kolone kojima se mogu dodeliti vrednosti iz kolona dataset-a.
 
Odgovor na temu

Koce
DBA
Serbia, Belgrade

Član broj: 59217
Poruke: 142
79.101.97.*



+1 Profil

icon Re: Kako upisati dataset u tabelu12.03.2009. u 15:20 - pre 152 meseci
Pa trebalo bi da taj dataset i ta tabela imaju veze da bi to mogao da uradis... kako da zna koju vrijednost gdje da stavi.... Mozes da probas nesto ovako:


Try
Dim lDA As New Data.SqlClient.SqlDataAdapter
If mGlobal.gCnn.State = ConnectionState.Closed Then mGlobal.gCnn.Open()
lDA.SelectCommand = New SqlClient.SqlCommand("Select ..... ", mGlobal.gCnn)

Dim builder As SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(lDA)
builder.GetUpdateCommand()
lDA.Update(gDS) ' to je ono sto ti treba
mGlobal.gCnn.Close()

Catch ex As Exception
MsgBox(ex.Message)
End Try


 
Odgovor na temu

sparc
Sladjan Parc

Član broj: 65760
Poruke: 134
91.150.127.*



Profil

icon Re: Kako upisati dataset u tabelu13.03.2009. u 07:33 - pre 152 meseci
Hvala na odgovoru,
mada mozda i tema nije za ovaj forum, nisam najbolje razumeo odgovor, ali zato sam problem resio na
dole dat nacin, koji radi ali mozda nije optimalan.

Prikazan je nacin preuzimanja kurne liste sa web servisa NBS. Voleo bih kad bi se neko
ukljucio da se kod optimizuje.

Protected Sub btnPreuzmi_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPreuzmi.Click
Dim proxy As New yu.nbs.webservices.TempExchangeRatesService
Dim auth As New yu.nbs.webservices.AuthenticationHeader
auth.LicenceID = 0
auth.UserName = "TempTest"
auth.Password = "TempTestPassword"
proxy.AuthenticationHeaderValue = auth
Dim ds As DataSet
Dim dg As DataGrid
dg = New DataGrid()
dg.ID = "dgList"
ds = proxy.GetCurrentExchangeRates(CDbl(3))
dg.DataSource = ds
dg.DataBind()

Dim thisTable As DataTable
For Each thisTable In ds.Tables
Dim row As DataRow
For Each row In thisTable.Rows
If thisTable.Rows.IndexOf(row) = 0 Then
Try
DodajKlistu(CDate(row.Item(1).ToString), CInt(row.Item(0).ToString))
Catch ex As Exception
MsgBox("Kursnu listu nije moguce dodati", MsgBoxStyle.Critical, "Upozorenje")
Exit Sub
End Try
End If

Try
DodajKurseve(CDate(row.Item(1).ToString), _
CInt(row.Item(0).ToString), _
row.Item(6).ToString, _
CInt(row.Item(9).ToString), _
0, _
CDbl(row.Item(11).ToString), _
0)
Catch ex As Exception
MsgBox("Postoji greska kod upisa kurseva", MsgBoxStyle.Critical, "Upozorenje")
End Try

Next
Next
Response.Redirect("~/Maticni/user/KursneListe.aspx")

End Sub
Sub DodajKlistu(ByVal Datum As Date, ByVal Broj As Integer)
Dim connStr As String
connStr = System.Configuration.ConfigurationManager.ConnectionStrings("wesConnectionString").ConnectionString

Dim sqlConnection1 As New SqlConnection(connStr)
Dim cmd As New SqlCommand
Dim rowsAffected As Integer

cmd.CommandText = "ImportkListe"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = sqlConnection1
cmd.Parameters.Add("@Datum", Data.SqlDbType.DateTime).Value = Datum
cmd.Parameters.Add("@Broj", Data.SqlDbType.Int).Value = Broj

sqlConnection1.Open()
rowsAffected = cmd.ExecuteNonQuery()
sqlConnection1.Close()

End Sub

Sub DodajKurseve(ByVal Datum As Date, _
ByVal Broj As Integer, _
ByVal deviza As String, _
ByVal paritet As Integer, _
ByVal kupovni As Double, _
ByVal srednji As Double, _
ByVal prodajni As Double)
Dim connStr As String
connStr = System.Configuration.ConfigurationManager.ConnectionStrings("wesConnectionString").ConnectionString

Dim sqlConnection1 As New SqlConnection(connStr)
Dim cmd As New SqlCommand
Dim rowsAffected As Integer

cmd.CommandText = "ImportKursevi"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = sqlConnection1
cmd.Parameters.Clear()
cmd.Parameters.Add("@Datum", Data.SqlDbType.DateTime).Value = Datum
cmd.Parameters.Add("@Broj", Data.SqlDbType.Int).Value = Broj
cmd.Parameters.Add("@Deviza", Data.SqlDbType.Char).Value = deviza
cmd.Parameters.Add("@Kupovni", Data.SqlDbType.Real).Value = kupovni
cmd.Parameters.Add("@Srednji", Data.SqlDbType.Real).Value = srednji
cmd.Parameters.Add("@Prodajni", Data.SqlDbType.Real).Value = prodajni
cmd.Parameters.Add("@Paritet", Data.SqlDbType.Int).Value = paritet


sqlConnection1.Open()
rowsAffected = cmd.ExecuteNonQuery()
sqlConnection1.Close()

End Sub
 
Odgovor na temu

[es] :: MS SQL :: Kako upisati dataset u tabelu

[ Pregleda: 1678 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.