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?
write a C++ program which take inputs from the user/keyboard and calculate his ZAKAT.
get the input from user may include
-Amount invested in business
-Amount given to other business partners as loan
-Amount payable to others
I made a prime number finder, it finds the nearest prime that is above and below any integer (Does not work that well with giant numbers.)
Made this in cpp.sh
Why would I need the x=y+1-1;?
x=y; just doesnt seem to work
Why is this?
And I know my coding ...
there are five tables (personTb, addressTb,churchTb) each holds data pertinent to an individual; (personAddress,personChurch) each hold the primary key for the person table and corresponding table IE personAddress holds primary key for addressTb.
both snippets work, my question is; Is my join correctly formatted?
select concat(personTb.p_fName,' ',personTb.p_mName,'. ',personTb.p_lName) ...