I work with Visual basic 2010 express and Sql server 2008 Express

I established Person and Specialist tables data base .I want to make Insert /update/ delete
Here object declarations in a module :

Public str As String 'string sqlcommand
    Public con As New SqlConnection("Data source =Sara\SQLEXPRESS ; initial catalog= ADHD_DIAGNOSIS_SYSTEM ;Integrated Security =True  ")
    Public com As SqlCommand
    Public DataSet As New DataSet()
    Public Specialistadapter As New SqlDataAdapter("Select * from SPECIALISTS ", con)
    Public Personadapter As New SqlDataAdapter("Select * from PERSON", con)

    Public SpecialistCommandBuilder As New SqlCommandBuilder(Specialistadapter)
    Public PersonCommandBuilder As New SqlCommandBuilder(Personadapter)
    '' declare tables
    Public tblPerson As DataTable
    Public tblSpecialist As DataTable
    Public tblSession As DataTable
    '' declare records
    Public PersonCurrent As DataRow
    Public SpecialistCurrent As DataRow

at load project this Sub main is called:

Specialistadapter.FillSchema(DataSet, SchemaType.Source, "SPECIALISTS")
        Specialistadapter.Fill(DataSet, "SPECIALISTS")
        'Fill second table
        Personadapter.FillSchema(DataSet, SchemaType.Source, "PERSON")
        Personadapter.Fill(DataSet, "PERSON")
        tblSpecialist = DataSet.Tables("SPECIALISTS")
        tblPerson = DataSet.Tables("PERSON")

when delete btn is clicked delete is called :
sub delete ()

Personadapter.DeleteCommand = New SqlCommand("delete from  PERSON where SSN = @PersonSSN", con)
        Personadapter.DeleteCommand.Parameters.Add("PersonSSN", SqlDbType.VarChar, 50, "SSN").Value = PersonForm.SSNTextBox.Text
 PersonCommandBuilder.GetDeleteCommand()
        Personadapter.Update(DataSet, "PERSON")
        MsgBox("Record deleted successfully")

But this code does not delete the record
:'(
Plz help me
:(

Edited 6 Years Ago by __avd: Remove [color] tags.

in Module

public FIND as string

Public Sub Insqry(ByVal STR As String)
    Dim cmd As New OleDbCommand(STR, CON)
    cmd.ExecuteNonQuery()
End Sub  

Public Sub CONOPEN()
    If CON.State = ConnectionState.Closed Then
        CON.Open()
    End If
End Sub

in delete btn
find="delete from <tblname> where <conditioin>;"
conopen
InsQry(FIND)
msgbox "Record Deleted Succefuly"

Edited 6 Years Ago by __avd: Added [code] tags.

This is C# code i need this code to convert into ASP.NET

protected void btn_Click(object sender, EventArgs e)
        {
string strConnection = ConfigurationSettings.AppSettings["connectionString1"];
            //Splitting ConnectionString to Extract Properties
            string[] spt1 = strConnection.Split(new Char[] { ';' });
            string serverName = "";
            string userName = "";
            string passWord = "";
            string currentyear = (DateTime.Now.Year.ToString().Substring(2, 2));
            //string CurrentDate = (DateTime.Now.Date .ToString());
            string serverdb = "EMSDB";

            //Table Name to copy data
            string tbname = txttblName.Text.ToString();


            //Looping to set connectionString Properties into Variables
            foreach (string s in spt1)
            {
                string[] spt2 = s.Split(new Char[] { '=' });
                if (spt2[0] == "Data Source") serverName = spt2[1];
                if (spt2[0] == "Database") serverdb = spt2[1];
                if (spt2[0] == "uid") userName = spt2[1];
                if (spt2[0] == "pwd") passWord = spt2[1];
                //if (spt2[0] == "ProviderName") provider = spt2[1];

            }



            //New Database Name
            string newdb = serverdb + "_NewDB" + currentyear;// +CurrentDate;
            //SMO Class Server Connection to Create New Database
            ServerConnection conn = new ServerConnection();
            conn.LoginSecure = false;
            conn.Login = userName;
            conn.Password = passWord;
            conn.ServerInstance = serverName;
            Server server = new Server(conn);

            // Get the Database to Transfer
            Database db = server.Databases[serverdb];
            
           db1.Create();
         
           // Setup transfer class
            // options to copy all objects
            // both Data and Schema or not
            Transfer t = new Transfer(db);
            t.CopyAllObjects = true;
            t.DropDestinationObjectsFirst = false;
            t.CopySchema = true;
            t.CopyData = false;
            t.DestinationLoginSecure = false;
            t.DestinationServer = serverName;
            t.DestinationLogin = userName;
            t.DestinationPassword = passWord;
            t.DestinationDatabase = newdb;
            t.Options.IncludeIfNotExists = true;

protected void btn_Click(object sender, EventArgs e)
        {
string strConnection = ConfigurationSettings.AppSettings["connectionString1"];
            //Splitting ConnectionString to Extract Properties
            string[] spt1 = strConnection.Split(new Char[] { ';' });
            string serverName = "";
            string userName = "";
            string passWord = "";
            string currentyear = (DateTime.Now.Year.ToString().Substring(2, 2));
            //string CurrentDate = (DateTime.Now.Date .ToString());
            string serverdb = "EMSDB";

            //Table Name to copy data
            string tbname = txttblName.Text.ToString();


            //Looping to set connectionString Properties into Variables
            foreach (string s in spt1)
            {
                string[] spt2 = s.Split(new Char[] { '=' });
                if (spt2[0] == "Data Source") serverName = spt2[1];
                if (spt2[0] == "Database") serverdb = spt2[1];
                if (spt2[0] == "uid") userName = spt2[1];
                if (spt2[0] == "pwd") passWord = spt2[1];
                //if (spt2[0] == "ProviderName") provider = spt2[1];

            }



            //New Database Name
            string newdb = serverdb + "_NewDB" + currentyear;// +CurrentDate;
            //SMO Class Server Connection to Create New Database
            ServerConnection conn = new ServerConnection();
            conn.LoginSecure = false;
            conn.Login = userName;
            conn.Password = passWord;
            conn.ServerInstance = serverName;
            Server server = new Server(conn);

            // Get the Database to Transfer
            Database db = server.Databases[serverdb];
            
           db1.Create();
         
           // Setup transfer class
            // options to copy all objects
            // both Data and Schema or not
            Transfer t = new Transfer(db);
            t.CopyAllObjects = true;
            t.DropDestinationObjectsFirst = false;
            t.CopySchema = true;
            t.CopyData = false;
            t.DestinationLoginSecure = false;
            t.DestinationServer = serverName;
            t.DestinationLogin = userName;
            t.DestinationPassword = passWord;
            t.DestinationDatabase = newdb;
            t.Options.IncludeIfNotExists = true;

Edited 6 Years Ago by __avd: Added [code] tags.

This article has been dead for over six months. Start a new discussion instead.