poojavb 29 Junior Poster

According to me ur Datatype is not correct....

try using

.Add("@callup", SqlDbType.VarChar)
.Add("@statecode", SqlDbType.VarChar) 

use SqlDbType instead of OleDbType

poojavb 29 Junior Poster

using select statement and in the where clause mention the criteria as ur combo box....and in ur reader assign the value to the text box....

 Try
     Dim myCommand As SqlCommand
     myCommand = New SqlCommand("SELECT  * FROM tablename where studentname='" & Combobox1.Text & "'", Connection)
     Dim reader As SqlDataReader = myCommand.ExecuteReader
     While reader.Read
           txtRollID.Text = reader("RollID")
     End While
     reader.Close()
Catch ex As Exception
     MsgBox("Error Connecting to Database: " & ex.Message)
End Try
poojavb 29 Junior Poster

the query works for a single table and not multiple tables.....it was showing some data type error....

anyways i got it working...
First I took the exact values that were there in the tables to text files and then used the same above code...and it worked...

poojavb 29 Junior Poster

Hello,

Can we perform bulk insert for SQL data?

I have the complete SQL data in text files. There are multiple tables and the corresponding text files.

I tried to do the bulk insert but always got some new error.

Please help me to get an answer.

My code

Imports System.IO
Imports System.Data.SqlClient
Public Class Form2

     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
          Dim FileName As String
          Dim dbstatus As Boolean
          Dim sr As StreamReader
          Dim line As String
          Dim linesCount As Integer
          Dim lines As String()
          Dim i, j As Integer
          Dim Names_Of_Tables() As String

          Dim myconn As SqlConnection = New SqlConnection
          dbstatus = Open_NDB_Connection(myconn)

          Dim dbCmd As SqlCommand = New SqlCommand()

          Names_Of_Tables = {"Local_IP_Config", "Login_Informations","Remote_IP_Config", "Restricted"}

          For i = 0 To Names_Of_Tables.Length - 1
               FileName = "D:\DATA\" & Names_Of_Tables(i) & ".txt"
               If File.Exists(FileName) Then
                    Debug.Print("Filename: " + FileName)
                    Debug.Print("Names_Of_Tables: " + Names_Of_Tables(i))
                    'If FileName = Names_Of_Tables(i) Then
                    sr = New StreamReader(FileName)
                    lines = IO.File.ReadAllLines(FileName)

                    linesCount = Integer.Parse(lines.Length)
                    Debug.Print(FileName + " lines = " + linesCount.ToString)
                    line = sr.ReadLine()
                    Try
                         For j = 0 To linesCount - 1
                              dbCmd = New SqlCommand("BULK INSERT " & Names_Of_Tables(i) & " FROM '" & FileName & "' WITH (FIELDTERMINATOR = '\t', ROWTERMINATOR = '\n')", myconn)
                              Debug.Print("Query: " + dbCmd.CommandText)
                              dbCmd.ExecuteNonQuery()
                              line = sr.ReadLine()
                         Next
                    Catch ex As Exception
                         MsgBox(ex.Message)
                    End Try

                    'End If
               Else
                    MsgBox("File " + FileName + " does not exists")
               End If
          Next
     End Sub
End Class

'Connection code is as follows

Imports …
poojavb 29 Junior Poster

JoptionPane returns the int values 0 or 1....
yes means 0 and no means 1....
if I select the No button with the Tab key and press Enter key it returns 0 instead of 1
and if I click on the No button with the help of mouse it gives the correct value that means 1.

poojavb 29 Junior Poster

Hello All,

I have a Java program which is using a JOptionPane in it.

eg. Are you sure u want to close the application?
Yes              No

When I click with the mouse on the No button it works correctly but if I select the No button using the TAB key and press enter key the application still closes.

Can anyone tell me whats going wrong

    public class WindowHandler extends WindowAdapter
{
    public void windowClosing(WindowEvent e)
    {
        int OptionChoosed=JOptionPane.showConfirmDialog(null, "<html><p><font color=\"#FF8C00\" " +
                "size=\"4\" face=\"Book Antiqua\">Close the Application ?"+
                "</font></p></html>" ,"Warning",JOptionPane.YES_NO_OPTION);    
        System.out.println(OptionChoosed);
        if (OptionChoosed==0)
        {
            try
            {
                if (databaseInformationModel != null)
                {       // may have failed to be initialized for some reason
                    JOptionPane.showMessageDialog(null,"ABCD" +OptionChoosed,"null",JOptionPane.WARNING_MESSAGE); //just a debugger
                    databaseInformationModel.close();   // we want to shut it down and compact it before exiting
                    System.exit(0);
                }
            }
            catch (Exception e1){e1.printStackTrace();}
        }
        else if (OptionChoosed==1)
        {
            System.out.println(OptionChoosed+"Do nothing");
        }
        JOptionPane.showMessageDialog(null,"OUT" +OptionChoosed,"null",JOptionPane.WARNING_MESSAGE); //just a debugger

    }//windowClosing
}//WindowHandler

I need the button to react to the mouse listener as well as the key listener depending on the users choice

poojavb 29 Junior Poster

Hello,

Is it possible to disable the windows key when the application is running??

Suppose I am running a particular application....and if the user press the windows key or clicked on the windows key on the task bar it shud prompt a message box that user is not allowed to press or click the windows key....

Can anyone help me on this???

poojavb 29 Junior Poster

u can create a class for the string characters only once and then call the class for the particular control in ur full project whenever required...

like below

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyTextField extends JTextField implements KeyListener,FocusListener
{
int size;
    public MyTextField(int size)
    {
        super(20);
        this.size=size;
        setFont(new Font("Palatino Linotype",0,15));
        addKeyListener(this);
        setDisabledTextColor(new Color(0,0,0));
        addFocusListener(this);
    }
    public void keyTyped(KeyEvent e)
    {   
        char ch=e.getKeyChar();     
            if(!(((ch<=90)&&(ch>=65))||((ch<=122)&&(ch>=97))||(ch==8)||(ch==127)))
            {
                if(ch==' ')
                    JOptionPane.showMessageDialog(this,"No space allowed.");
                else
                    JOptionPane.showMessageDialog(this,"Please enter alphabets only.");
                e.setKeyChar('\0');

            }
        if(getText().length()>size-1)
        e.setKeyChar('\0');
    }   
    public void keyPressed(KeyEvent e){}
    public void keyReleased(KeyEvent e){}

    public void focusLost(FocusEvent fe)
    {
        setBackground(new Color(255,255,255));
    }
    public void focusGained(FocusEvent fe)
    {

        setBackground(new Color(200,255,200));

    }
}

to make a reference in ur SNMPInquisitor or the other class call as below wherever u need...

MyTextField jt;

how u write

JTextField jt; 

same way....

it is convienent coz with this one class we can write in complete project and if changes are required change in once class only....

poojavb 29 Junior Poster

if u use the code what jezguitarist30 has given u can face one issue that is...
Suppose there are 10 Staffs in the database i.e. Staff ID - 0010 will be the last id in ur database
and in case Staff ID - 0003 is deleted
and then again if u go and add some new id then according to ur count it will get 10
and then it will be difficult to add since it will be a primary key issue....
think on this....

poojavb 29 Junior Poster

Its Mrs. Pooja :)

in load event u can call

dgvStaff.DataSource=GetData()
poojavb 29 Junior Poster
Dim myCommand As SqlCommand
myCommand = New SqlCommand("SELECT StaffCode,StaffName,Gender FROM Staff WHERE StaffCode='" & Me.txtStaffCode & "'", cnn)
Dim reader As SqlDataReader = myCommand.ExecuteReader
If reader.HasRows()
    While reader.Read
                    'txtStaffCode.Text = reader("StaffCode")
                    txtStaffName.Text = reader("StaffName")
                    cboGender.Text = reader("Gender")
    End While
Else
    MsgBox("No record found.","Not Found")
End If
reader.Close()
poojavb 29 Junior Poster

u can try the below code

Public Function GetData() As DataView
        'Open_DB_Connection()
        Dim SelectQry = "SELECT * FROM TableName"
        Dim SampleSource As New DataSet
        Dim TableView As DataView
        Try
            Dim SampleCommand As New SqlCommand()
            Dim SampleDataAdapter = New SqlDataAdapter()
            SampleCommand.CommandText = SelectQry
            SampleCommand.Connection = Connection
            SampleDataAdapter.SelectCommand = SampleCommand
            SampleDataAdapter.Fill(SampleSource)
            TableView = SampleSource.Tables(0).DefaultView
        Catch ex As Exception
            'Debug.Print("Exception: ")
            Throw ex
        End Try
        'Close_DB_Connection()
        Return TableView
End Function
poojavb 29 Junior Poster

G_Waddell - I browsed through the link but it shows various connections for instance and the local host...

I just want to display the SQL server available on the local machine in a combo box or a list box...

Can anyone tell me how to get the SQL server name from the local machine...no using database connection...and no network servers...
I tried seraching everything...

poojavb 29 Junior Poster

Actually the server name differ from PC to PC...when my colleagues do coding their server name is localhost\SQLexpress but same is not the condition in my PC its only localhost and so their code wont work in my machine and then I have to do the changes according to my SQL server name...and we are not sure what will be the one on clients machine....

what I want to do is get the servername before the database connections proceed...

is it possible to get the localhost name of the same machine....

poojavb 29 Junior Poster

For updating

'Open Connection
Dim upCommand As OleDbCommand
upCommand = New OleDbCommand("Update Value set Colname ='" + Textbox1.Text + "'", Connection)
upCommand.ExecuteNonQuery()
'Close connection

For inserting

'Open Connection
Dim myCommand As OleDbCommand
myCommand = New OleDbCommand("INSERT INTO Tablename Values('" + txtID.Text + "','" + txtName.Text + "')", Connection)
Dim DBReader As OleDbDataReader = myCommand.ExecuteReader
DBReader.Close()
'Close Connection
poojavb 29 Junior Poster

Hello Friends,

Can anyone tell me how to find the list of SQL servers on the local machine...and not the network...

I searched in google but everywhere its for the list of SQL servers on network....I just want my PC SQL server name....

Is it possible to get it?

Thanks in advance
Pooja

poojavb 29 Junior Poster

Can u check if the prvider string u are entering is correct....coz ur code worked for me but I just changed my provider...

below is my connection string....

 connectionDatabase = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0.;Data Source=pacs_skan.mdb;Persist Security Info=False;")

for debugging u need to add the debug.print statements .i.e.

Debug.Print(selectedStaffName.ToString())

the debug statements can be viewed in ur immediate window
Debug -> Windows -> Immediate

there are also spaces in ur fieldnames... try giving [ ] to ur field name like [Staff ID]

Its not a good practive to give spaces in ur field names...

poojavb 29 Junior Poster

May be u get some idea from here....

class constNumtoLetter
  {
      String[] unitdo ={"", " One", " Two", " Three", " Four", " Five",
         " Six", " Seven", " Eight", " Nine", " Ten", " Eleven", " Twelve",
         " Thirteen", " Fourteen", " Fifteen",  " Sixteen", " Seventeen", 
         " Eighteen", " Nineteen"};
      String[] tens =  {"", "Ten", " Twenty", " Thirty", " Forty", " Fifty",
         " Sixty", " Seventy", " Eighty"," Ninety"};
      String[] digit = {"", " Hundred", " Thousand", " Lakh", " Crore"};
     int r;


      //Count the number of digits in the input number
      int numberCount(int num)
      {
          int cnt=0;

          while (num>0)
          {
            r = num%10;
            cnt++;
            num = num / 10;
          }

            return cnt;
      }


      //Function for Conversion of two digit

      String twonum(int numq)
      {
           int numr, nq;
           String ltr=\"";

           nq = numq / 10;
           numr = numq % 10;

           if (numq>19)
             {
           ltr=ltr+tens[nq]+unitdo[numr];
             }
           else
             {
           ltr = ltr+unitdo[numq];
             }

           return ltr;
      }

      //Function for Conversion of three digit

      String threenum(int numq)
      {
             int numr, nq;
             String ltr = "";

             nq = numq / 100;
             numr = numq % 100;

             if (numr == 0)
              {
              ltr = ltr + unitdo[nq]+digit[1];
               }
             else
              {
              ltr = ltr +unitdo[nq]+digit[1]+" and"+twonum(numr);
              }
             return ltr;

      }

}

 class originalNumToLetter

   {

      public static void main(String[] args) throws Exception
      {

          //Defining variables q is quotient, r is remainder

          int len, q=0, r=0;
          String ltr = " ";
          String Str = "Rupees";
          constNumtoLetter n = new constNumtoLetter();
          int num = Integer.parseInt(args[0]);

          if (num …
poojavb 29 Junior Poster

Can u show ur code and what controls are u using to show ur record???

poojavb 29 Junior Poster

Just an idea...

I had to save the data as INP1 - first 3 characters and last integer

We cant save the alphanumeric as integer

but what I had done was....I had one temp table....which had the integer value...
every time I need to increment the value I used to check the value in that table and update in my new table....that had datatype as varchar...so everytime it used to get incremented correctly....after the insert statement then update the temp table by 1....

poojavb 29 Junior Poster

When ur application starts for the very first time allow the user to save the database location in a particular text file....

for that u have to give the openfiledialog box that will take the file location and save the location....

so that during the connection u can get the database path details from the text file itself....

the next time onwards the user shud only check if the filename is present in ur textfile...if the textfile is empty or the database is invalid it shud prompt the user with error msg and again ask to relocate the database...

if its not clear do post again...will help u further...

poojavb 29 Junior Poster

Can u show u connection code....

poojavb 29 Junior Poster

ur insert query is also incorrect with the quotation marks

SqlCommand sqlcmd = new SqlCommand("INSERT INTO TABLE1 (Name, Address, Email, Phone, Dob) VALUES ('"+nametbox.Text+"','"+addtbox.Text+"','"+mailtbox.Text+"','"+phonetbox.Text+"','"+dobtbox.Text+"')");

if ur are not using the parameters

poojavb 29 Junior Poster

everytime the form loads it first triggers the resize event and then the load event

try to debug the code u will understand....using step over and step into

poojavb 29 Junior Poster

Can u show ur code???

poojavb 29 Junior Poster

Write the below part in ur html source code of the button

 <asp:Button ID="Button1" runat="server" Text="Button" Width="141px"  OnClientClick="window.open('WebForm1.aspx', 'OtherPage','top=0, left=0, width=500, height=500, menubar=yes,toolbar=yes,status=1,resizable=yes');"/>
poojavb 29 Junior Poster

Hope this helps u....

'Open Connection
Dim myCommand As SqlCommand
myCommand = New SqlCommand("SELECT ProdName from HMS.dbo.Product where Inventory < ReorderLimit", Connection)
Dim reader As SqlDataReader = myCommand.ExecuteReader
While reader.Read()
      For RCnt As Integer = 0 To dgvInventory.Rows.Count - 1
          If dgvInventory.Rows(RCnt).Cells("Product").Value = reader("ProdName") Then
             dgvInventory.Rows(RCnt).DefaultCellStyle.BackColor = Color.MediumPurple
             dgvInventory.Rows(RCnt).DefaultCellStyle.ForeColor = Color.White
          End If
      Next
End While
reader.Close()
'Close Connection
poojavb 29 Junior Poster

What do u actually want to do in ur coding???

set the combo box value for 1 combox and then on the selection change event get the remaining values....

if I am wrong then can you be little more clear....

poojavb 29 Junior Poster

Something like this might help u...

'Open_DB_Connection
Try
     Dim myCommand As SqlCommand
     myCommand = New SqlCommand("SELECT  * FROM Tablename where ID='" & combobox1.Text & "'", Connection)
     Dim reader As SqlDataReader = myCommand.ExecuteReader
     While reader.Read
           txtID.Text = reader("ID")
           txtName.Text = reader("Name")
           txtCost.Text = reader("Cost")
     End While
     reader.Close()
Catch ex As Exception
     MsgBox("Error Connecting to Database: " & ex.Message)
End Try
'Close_DB_Connection
poojavb 29 Junior Poster

try something like this

set the y axis of the datagridview as u want....

u can also write the below code in load as well as form resize event so that if the form is resized even the controls will be resized...

          DataGridView1.Size = New System.Drawing.Size(Me.Width / 2 - 100, 300)
          DataGridView1.Left = Me.Left + 50

          DataGridView2.Size = DataGridView1.Size
          DataGridView2.Left = Me.Width / 2 + 50

          Button1.Top = Me.Height - Button1.Height - 20
          Button1.Left = Me.Width - Button1.Width - 20
poojavb 29 Junior Poster

u can write in the textbox textchange event with the sql query using the like condition....

'Open Connection
Try
   Dim myCommand As New OleDbCommand
   With myCommand
        .CommandText = "SELECT ID , (FirstName +' '+LastName) as Name FROM TableName where  ID like '" & Textbox1.Text & "%" + "' order by ID"
        .CommandType = CommandType.Text
        .Connection = Connection
   End With
   Dim dt As New DataTable
   dt.Load(myCommand.ExecuteReader)
   With DatagridView1
        .AutoGenerateColumns = True
        .DataSource = dt
   End With
Catch ex As Exception
   MsgBox("Error in select query: " + ex.Message)
End Try
'Close Connection
poojavb 29 Junior Poster

hope this helps u

System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(<script language='javascript'>");
        sb.Append("window.open('Default2.aspx', 'CustomPopUp',");
        sb.Append('top=0, left=0, width=500, height=500, menubar=yes,toolbar=yes,status=1,resizable=yes'));

        sb.Append("</script>");
poojavb 29 Junior Poster

According to ur code u r creating the new instance of the FormX and then checking the condition.....

if u know the form name then just give the name and then the condition...dont create an instance...

poojavb 29 Junior Poster

Try this...keep the form 2 code as it is....

Imports System.IO

Public Class Form1

     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
          If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
               Dim dbfFileFolder As String = OpenFileDialog1.FileName
               Dim stFileName As String
               Dim MyFile As FileInfo = New FileInfo(dbfFileFolder)
               stFileName = MyFile.Name
               If stFileName = "GNDITEM.DBF" Then
                    Form2.ShowDialog() 'this is my Form2
               Else
                    MsgBox("error")
               End If
          End If
     End Sub
End Class
poojavb 29 Junior Poster

as u are also using asp.net the show method dont go with it....

response.redirect is the method to redirect it to the other form in asp.net

poojavb 29 Junior Poster

Just an info....

Actually ur sql query wont help u....
if u select the first "01" from sessionID , second "02" from courseID , third "02" from levelID then the database would store something like 01020200001

suppose u have selected the first "01" from courseID and when u run the query the value returned will be 01020200001 and this value will be added by 1,then it would return something else which will create a chaos....

poojavb 29 Junior Poster

If it is the connection string do mention the type of database u r using...
Access
SQl or something else....

poojavb 29 Junior Poster

the line variable u have declared inside ur do while loop and calling until the line variable is nothing....

declare the line variable before the do while loop....

Dim line As String() = Split(wholeingrediant, ",")

Make sure that the user enters only numeric values wherever required....

poojavb 29 Junior Poster

Got the answer....

'Form3.vb

Public Class Form3
     Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
          StartPosition = FormStartPosition.CenterScreen
     End Sub

     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
          Me.Close()
     End Sub
End Class

'Form2.vb

Public Class Form2
     Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
          WindowState = FormWindowState.Maximized
          FormBorderStyle = Windows.Forms.FormBorderStyle.None
     End Sub
End Class

'Form1.vb

Public Class Form3
     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
          Form2.BackColor = Color.DarkGray
          Form2.TransparencyKey = BackColor
          Form2.Opacity = 0.7
          Form2.Show()
          Form3.ShowDialog()
          Form2.Close()
     End Sub

     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
          Me.WindowState = FormWindowState.Maximized
     End Sub
End Class
poojavb 29 Junior Poster

whatever waqasaslammmeo has given that is correct.... what else do u want to display in ur datetimepicker??? by setting the format to time and setting the showupdown property as true the calendar should not drop down....

what do u mean by changing time....the up down buttons will change the time...even u can bring ur cursor over there and make the changes accordingly....

poojavb 29 Junior Poster

when u click on the calculate button make sure that both the text boxes are not empty...if so prompt the error....

if textbox1.Text="" or Textbox2.Text="" then
    Msgbox("Mandatory Info")
else
    'ur calculation code
End If

below code u can do for entering only numbers....it has to be written in ur textbox key press event

If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
      e.Handled = True
End If
If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
      e.Handled = False
End If

What does ur textbox3, textbox4 and textbox5 hold???

poojavb 29 Junior Poster

U need to insert this query in the place where u want to fetch the employee names...

how are u entering the date....is it a textbox or a datetimepicker???

poojavb 29 Junior Poster

You want to search the employee on basis of date and month....

so u have to modify ur query accordingly....

    select ID, FName, MobNo, Email, BirthDate
    FROM Tablename
    where
    Day(BirthDate) = day(GETDATE())  and
    month(BirthDate) = month(GETDATE())

ur getdate() should be according to the datetimepicker date and month value....

hope it gives u an idea....

poojavb 29 Junior Poster

can u be more clear....how many textboxes will u be having

poojavb 29 Junior Poster

Ok...I got the answer....

use form2.ShowDialog()

this will not allow the user to move to the parent form unless the child form is closed...

can anyone tell me how to add the grayed out screen???

poojavb 29 Junior Poster

Hello Friends,

I need help to disable the parent window form as soon as the user will open the child form....

for eg...consider daniweb...when we click on member login the background form gets grayed out....

Disabling the form is not the option cause it will just disable all the controls of the form....but I need a grayed out screen between the current child form and the parent form....

note - the parent form is not the MDI form...it is just a normal window form

and when the child form is open and if the user clicks on the main form without closing the child form then the screen should show some movement...

I tried disabling the form...changing the background of the form to opaque....but could not get through it....

poojavb 29 Junior Poster

mycommand.CommandText can also help u to return the entire query.....in ur debug.print.....

poojavb 29 Junior Poster

M1234ike - did u try what I have given???

poojavb 29 Junior Poster

Right click on ur database and select add new database....ur new database will be different...it wont be added in ur system database...

after ur database is created right click and then select new table to add ur data....

ur tree view in database will be

Servername
    Database
        - System Databases
        - YourNewDatabase
        - and so on
poojavb 29 Junior Poster

If you would have been storing the file path then you could have used the following code

          Dim img As New DataGridViewImageColumn()
          Dim inImg As Image = Image.FromFile("C:\Users\pooja\Desktop\images\abc\Logo.jpg")
          img.Image = inImg
          DataGridView1.Columns.Add(img)
          img.HeaderText = "Image"
          img.Name = "img"