Iam newbie to vb.net .iam creating a registration form.iam also creating database table in sql server.now how to store record in that table.how to do this?
make a module to connect vb.net with sql server.
add this code to module :
Imports System.Data Imports System.Data.SqlClient Module Connect Public conn As SqlConnection Public Function GetConnect() conn = New SqlConnection("Server = YourServerName;" & "initial Catalog = yourDatabaseName;" & " Trusted_Connection=yes") Return conn End Function End Module
you can call the function on the module to connect with sqlserver on each form. so u can open connection and close.
like this ex:
conn = GetConnect() conn.Open() ..... ..... conn.Close()
What a registration form you want to build?
put a print screen?
this simple following code to add/store data to sqlserever :
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim check As Integer Dim conn As SqlConnection Dim cmdmedical As New SqlCommand Dim cmdmedical1 As New SqlCommand Dim damedical As New SqlDataAdapter Dim dsmedical As New DataSet Dim dtmedical As New DataTable If cmbNis.SelectedIndex = -1 Or cmbBloodType.SelectedIndex = -1 Or txtdisease.Text = "" Or txtAnomalyBody.Text = "" Or txtHeight.Text = "" Or txtBerat.Text = "" Then MsgBox("Student Medical Data is not completed", MsgBoxStyle.OKOnly) Else If MsgBox("Are you sure to store student medical data with Nis : " & cmbNis.SelectedItem & " ?", MsgBoxStyle.OKCancel, "Input confirm") = MsgBoxResult.Cancel Then ' do nothing Else Try conn = GetConnect() conn.Open() cmdmedical = conn.CreateCommand cmdmedical.CommandText = "SELECT * FROM medical WHERE Nis='" & Trim(cmbNis.SelectedItem) & " ' " damedical.SelectCommand = cmdmedical damedical.Fill(dsmedical, "medical") dtmedical = dsmedical.Tables("medical") If (dtmedical.Rows.Count > 0) Then MsgBox("medical dengan Nis " & Trim(cmbNis.Text) & " Sudah ada didata base", MsgBoxStyle.OKOnly, "Message :") Else cmdmedical1 = conn.CreateCommand cmdmedical1.CommandText = "INSERT INTO medical(Idmedical, Nis, BloodType, Disease,AnomalyBody,Height,Weight) VALUES('" & Trim(idmedical.Text) & "','" & Trim(cmbNis.SelectedItem) & "','" & Trim(cmbBloodType.SelectedItem) & "','" & Trim(txtdisease.Text) & "','" & Trim(txtAnomalyBody.Text) & "','" & Trim(txtHeight.Text) & "','" & Trim(txtWeight.Text) & "')" check = cmdmedical1.ExecuteReader.RecordsAffected() If check > 0 Then MsgBox("Student with Nis " & Trim(cmbNis.Text) & " succesfully added", MsgBoxStyle.OKOnly, "Message :") Else MsgBox("Student with Nis " & Trim(cmbNis.Text) & " failure to added", MsgBoxStyle.OKOnly, "Message :") End If Refresh_Form() conn.Close() End If Catch ex As Exception MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error!!") End Try End If End If End Sub
I want a full tutorial for sql connection from the beginning that means from the designing part.
imports system.data imports system.data.sqlclient Public class form1 private sub button1_click (byval sender as system.object.....) dim con as sqlconnection = new sqlconnection ( _ "server = server name"; database = dbase name; & _ user id = server id; password = server password;") dim objcommand as sqlcommand = new sql command with objcommand .connection = con .commandtext = "INSERT INTO tablename" & _ "(enter fields with comma seperating them)" & _ "VALUES (values for each field with a comma just as above)" end with con.open() objcommand.executenonquery() con.close
how to put printscreen hir?
I am currently working on a program to track my mile for my monthly expense report for work. Everything is working great, however, I can not for the life of ...
I am trying to understand the SynchronizedMap and I ran the below code. I get the below Output with an exception. According to my understanding the exception is caused when ...
I am trying to make this form to clear after being submited. As it is now the form submits, however, the input fields do not clear and when ...