Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with code pls....
Message
From
20/10/2003 23:03:09
 
 
To
All
General information
Forum:
ASP.NET
Category:
Databases
Title:
Help with code pls....
Miscellaneous
Thread ID:
00840534
Message ID:
00840534
Views:
51
HERES THE CODE THAT I HAD WRITTEN AND IT SEEMS TO WORK:

Sub Button1_Click(sender As Object, e As EventArgs)

Dim connectionString As String = "server='Merlin'; trusted_connection=true; database='Solotest'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)

Dim queryString As String = "INSERT INTO [Sturecs] ([appdate],[studentid],[firstname],[midname],[lastname],[address1],[city],[studzip],[paddress1],[homephone],[birthplace],[birthdate],[national],[studgen],[cvlstat],[progcod],[special],[major],[minor],[religion],[baptized],[acrno],[guardfname],[guardmname],[guardlname],[relatiOnsh],[selfemplyd],[employed],[occupation],[oficename],[oficeadd],[oficephone],[oficefax],[oficeemail],[elemschl],[highschl],[college],[masters],[edate],[hdate],[cdate],[mdate],[esono],[hsono],[csono],[msono],[cmajor],[cminor],[mmajor],[mminor]) VALUES (@date,@tempno,@fnam,@mnam,@lnam,@cadd,@city,@zip,@padd,@contno,@pob,@dob,@natl,@gen,@cvlstat,@prgcod,@espec,@emajor,@eminor,@religion,@bapt,@acr,@gfnam,@gmnam,@glnam,@grel,@emplyd,@semplyd,@gocc,@goffnam,@goffadd,@goffph,@gofffax,@goffeadd,@eschl,@hschl,@cschl,@mschl,@edgrad,@hdgrad,@cdgrad,@mdgrad,@esono,@hsono,@csono,@msono,@cmajor,@cminor,@mmajor,@mminor)"
'
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbcommand.parameters.add(New SQLParameter("@date", textbox1.text))
dbcommand.parameters.add(New SQLParameter("@tempno", textbox2.text))
dbcommand.parameters.add(New SQLParameter("@fnam", textbox3.text))
dbcommand.parameters.add(New SQLParameter("@mnam", textbox4.text))
dbcommand.parameters.add(New SQLParameter("@lnam", textbox5.text))
dbcommand.parameters.add(New SQLParameter("@cadd", textbox6.text))
dbcommand.parameters.add(New SQLParameter("@city", textbox7.text))
dbcommand.parameters.add(New SQLParameter("@zip", textbox8.text))
dbcommand.parameters.add(New SQLParameter("@padd", textbox9.text))
dbcommand.parameters.add(New SQLParameter("@contno", textbox10.text))
dbcommand.parameters.add(New SQLParameter("@pob", textbox11.text))
dbcommand.parameters.add(New SQLParameter("@dob", textbox12.text))
dbcommand.parameters.add(New SQLParameter("@natl", textbox13.text))
dbcommand.parameters.add(New SQLParameter("@gen", radiobuttonlist1.SelectedItem.value))
dbcommand.parameters.add(New SQLParameter("@cvlstat", radiobuttonlist2.SelectedItem.value))
dbcommand.parameters.add(New SQLParameter("@prgcod", textbox14.text))
dbcommand.parameters.add(New SQLParameter("@espec", textbox16.text))
dbcommand.parameters.add(New SQLParameter("@emajor", textbox17.text))
dbcommand.parameters.add(New SQLParameter("@eminor", textbox18.text))
dbcommand.parameters.add(New SQLParameter("@religion", textbox20.text))
dbcommand.parameters.add(New SQLParameter("@bapt", textbox21.text))
dbcommand.parameters.add(New SQLParameter("@acr", textbox22.text))

dbcommand.parameters.add(New SQLParameter("@gfnam", textbox23.text))
dbcommand.parameters.add(New SQLParameter("@gmnam", textbox24.text))
dbcommand.parameters.add(New SQLParameter("@glnam", textbox25.text))
dbcommand.parameters.add(New SQLParameter("@grel", textbox26.text))
dbcommand.parameters.add(New SQLParameter("@emplyd", radiobuttonlist3.SelectedItem.value))
dbcommand.parameters.add(New SQLParameter("@semplyd", radiobuttonlist4.SelectedItem.value))

dbcommand.parameters.add(New SQLParameter("@gocc", textbox27.text))
dbcommand.parameters.add(New SQLParameter("@goffnam", textbox28.text))
dbcommand.parameters.add(New SQLParameter("@goffadd", textbox29.text))
dbcommand.parameters.add(New SQLParameter("@goffph", textbox30.text))
dbcommand.parameters.add(New SQLParameter("@gofffax", textbox31.text))
dbcommand.parameters.add(New SQLParameter("@goffeadd", textbox32.text))

dbcommand.parameters.add(New SQLParameter("@eschl", textbox33.text))
dbcommand.parameters.add(New SQLParameter("@hschl", textbox34.text))
dbcommand.parameters.add(New SQLParameter("@cschl", textbox35.text))
dbcommand.parameters.add(New SQLParameter("@mschl", textbox36.text))

dbcommand.parameters.add(New SQLParameter("@edgrad", textbox37.text))
dbcommand.parameters.add(New SQLParameter("@hdgrad", textbox38.text))
dbcommand.parameters.add(New SQLParameter("@cdgrad", textbox39.text))
dbcommand.parameters.add(New SQLParameter("@mdgrad", textbox40.text))

dbcommand.parameters.add(New SQLParameter("@esono", textbox41.text))
dbcommand.parameters.add(New SQLParameter("@hsono", textbox42.text))
dbcommand.parameters.add(New SQLParameter("@csono", textbox43.text))
dbcommand.parameters.add(New SQLParameter("@msono", textbox44.text))

dbcommand.parameters.add(New SQLParameter("@cmajor", textbox45.text))
dbcommand.parameters.add(New SQLParameter("@cminor", textbox46.text))

dbcommand.parameters.add(New SQLParameter("@mmajor", textbox47.text))
dbcommand.parameters.add(New SQLParameter("@mminor", textbox48.text))


Dim rowsAffected As Integer = 0
dbConnection.Open

rowsAffected = dbCommand.ExecuteNonQuery

dbConnection.Close

End Sub


HERES WHAT I PLAN TO DO NEXT....

i have a table....

table name = parmcounters
field name = studentid value = "20030001"

now what i want to do is store the incremented studentid value in the "sturecs" table and also save the same value in the parmcounters table....

many had suggested like this...

INSERT INTO TargetTbl Select max(pstudentid) FROM SourceTable

others....


OleDbConnection conn = new OleDbConnection("Provider=blahblahblah...");

OleDbCommand cmd = new OleDbCommand("SELECT pStudentId FROM ParmStudId WHERE ... blahblahblah...", conn);

conn.Open();
int LastStudId = (int) cmd.ExecuteScalar();
conn.Close();

cmd = new OleDbCommand("UPDATE .... SET StudentId = @StudentId", conn);

cmd.Parameters.Add("@StudentId",OleDbType.Integer).Value = LastStudId + 1;

cmd.ExecuteNonQuery();

conn.Close();

.............now I REALLY Dont know how to do this in SQL...can you help me?
Next
Reply
Map
View

Click here to load this message in the networking platform