poojavb 29 Junior Poster

ur welcome....if it helped u dont forget to mark the thread as solved...

poojavb 29 Junior Poster
Me.Visible = False

try this :)

poojavb 29 Junior Poster

" The optimum value is 13 at House 1 and House 2"

In this is 13 ur row number??

As I understood u want to display the row number of the item which will be clicked

Dim MaxVal As Integer
For a = 0 To DataGridView1.RowCount - 1
    MaxVal = DataGridView1.CurrentCell.RowIndex + 1
Next
MsgBox("The Optimum Value is " & MaxVal, 1, "Optimum Choice")

Please correct me if u need something else....

poojavb 29 Junior Poster

Just displaying code is not enough for us to understand ur problem....do explain ur problem in detail...

poojavb 29 Junior Poster

May be u shud post this code under jsp section....

in this section we can help u with queries

poojavb 29 Junior Poster

u can also try to first clear the combo box items before adding the values to it....

poojavb 29 Junior Poster

Check which is ur startup form....if ur startup form is the same as the one u r closing then it will close the complete application....

dont use the me.close or me.dispose....use Me.Hide and try....

to check ur startup form click on Project -> Projectname properties -> Application tab -> Startup form

poojavb 29 Junior Poster

checkbox1 - name
checkbox2 - date

give conditions in such a way that

if checkbox1.checked = true then
'ur sql query which will show the result in datagridview
elseif checkbox2.checked = true then
'ur sql query
elseif checkbox1.checked = true and checkbox2.checked = true then
'ur sql query
else 'means if both are unchecked then display error or if u want to display all details of the table
'whatever u need
End if
M.Waqas Aslam commented: very nice one , Pooja , simple and clear. +4
poojavb 29 Junior Poster

I guess if u post this in ASP.net u might get some help....

poojavb 29 Junior Poster

Whatever Jim has given it works...add few more lines of code

Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click 'checked on button click
    Dim found As Boolean = InListView(ListView1, ComboBox1.Text)
    If found = True Then
        MsgBox("Exists")
    Else
        'MsgBox("No")
        ListView1.Items.Add(ComboBox1.Text)
    End If
End Sub

Private Function InListView(lvw, text) As Boolean
    For Each item As ListViewItem In lvw.items
        If item.Text = text Then Return True
    Next
    Return False
End Function
poojavb 29 Junior Poster

you forgot the word Add....

it shud be Listview1.Items.Add and then the reader....

    Try
        Dim myCommand As SqlCommand
        myCommand = New SqlCommand("SELECT  * FROM DoctorRegister ", Connection)
        Dim reader As SqlDataReader = myCommand.ExecuteReader
        While reader.Read
            ListView1.Items.Add(reader.Item("FirstName")).Selected = True
        End While
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

selectedItem is not the property for listview.....

ListView1SelectedItem = reader.Item("PERSON")

poojavb 29 Junior Poster

set a masked Text box and set the mask as 00,000,000 and the database datatype can be varchar to retrieve this data....hope it helps u....

poojavb 29 Junior Poster

if u want a clear cell that use "" instead of Test4...

It will be good enough if u be more specific....n number of people will be able to help u....

poojavb 29 Junior Poster

Hey thanks...it worked perfectly fine...even I needed the same....Thanks _avd

poojavb 29 Junior Poster

write below code in ur button click event
textbox2 is the field where u will enter number

  MsgBox(ConvertNum(TextBox2.Text))

Then write the below function

 Public Shared Function ConvertNum(ByVal Input As Long) As String 'Call this function passing the number you desire to be changed
        Dim output As String = Nothing
        If Input < 1000 Then
            output = FindNumber(Input) 'if its less than 1000 then just look it up
        Else
            Dim nparts() As String 'used to break the number up into 3 digit parts
            Dim n As String = Input 'string version of the number
            Dim i As Long = Input.ToString.Length 'length of the string to help break it up

            Do Until i - 3 <= 0
                n = n.Insert(i - 3, ",") 'insert commas to use as splitters
                i = i - 3 'this insures that we get the correct number of parts
            Loop
            nparts = n.Split(",") 'split the string into the array

            i = Input.ToString.Length 'return i to initial value for reuse
            Dim p As Integer = 0 'p for parts, used for finding correct suffix
            For Each s As String In nparts
                Dim x As Long = CLng(s) 'x is used to compare the part value to other values
                p = p + 1
                If p = nparts.Length Then 'if p = number of elements in the array then we need to do something different
                    If x <> 0 Then
                        If CLng(s) < 100 Then
                            output = output & " And " & …
poojavb 29 Junior Poster
select a.item_number, a.itemdesc,c.colordescription,m.monthdescription from article a, colors c , month m where a.colornumber=c.colornumber and a.monthnumber=m.monthnumber
poojavb 29 Junior Poster

Write the event in combobox1 selectediIndex change event...make correct connections

Try
   Dim myCommand As New SqlCommand
   With myCommand
        .CommandText = "SELECT ordernumber,orderdate,itemname,quantity,RepairNumber FROM orderstable WHERE OrderNumber = '" & ComboBox1.Text & "'"
        .CommandType = CommandType.Text
        .Connection = conn
   End With
   Dim dt As New DataTable
   dt.Load(myCommand.ExecuteReader)
   With DatagridView1
        .AutoGenerateColumns = True
        .DataSource = dt
   End With
Catch ex As Exception
   Throw ex
End Try
poojavb 29 Junior Poster

try the below text for all the textboxes keypress event...

   'accepts only numbers
    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

This will be too lengthy I guess...coz u will have to code for all 20 text boxes key press....

else create a function similar to it and call the function in key press event

poojavb 29 Junior Poster

Is fullname alos a columnname in the table or just an alias u r giving to the concatenation of fname and lname

if it is a column name then I guess it wont go into the column else if it an alias then try below code

SELECT DISTINCT DEV_user_registration.reg_fname + ' ' + DEV_user_registration.reg_lname AS 'Fullname'
FROM DEV_user_registration
WHERE DEV_user_registration.reg_agent = 'Yes'
AND DEV_user_registration.reg_fname + ' ' + DEV_user_registration.reg_lname = '$_GET[agent_name]' ";

I guess it shud be this way

poojavb 29 Junior Poster

what type of database are u using....coz the query is different in SQL and access

poojavb 29 Junior Poster

to display data in the datagrid use the below code and then call the method with datagridview
Note- in select query call only the fields that u want to display in your datagridview1

Public Function GetData() As DataView
        'open connection
        Dim SelectQry = "SELECT * FROM Pricelist WHERE [SECURITY] ='" & Me.cboCompany.SelectedItem & "'"
        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 connection
        Return TableView
    End Function

and when calling datagrid write the following code like in button click or form load event...

Datagridview1.DataSource = GetData()

Hope this helps you

poojavb 29 Junior Poster

Is your splash screen the startup form??? if so try to make it as visible= false....
if it is a start up form and u try to close the splash screen then the complete application will exit,,,

poojavb 29 Junior Poster

U can directly use the text boxes instead of using property

just giving an example

If I want a value from form1 to form2 then I use following way

code in form1

Textbox1.Text=Form2.Label1.Text

In this way it wont open a new form....In your code u have used

Dim obj As New Form2

so u are getting a new form...just pass variables with form instead of creating property and also u can call the hide() and show() methods of the form

poojavb 29 Junior Poster

If u want the datagridview to be empty at first set the datasource to nothing ....

i tried the same code but as soon as any value in text box changes it shows me the datagrid with values in database.....check ur connection...is it fine???

poojavb 29 Junior Poster

If u need to find the database table names....use the query which u have used in place of the query what i have used and then save the column names in variable

poojavb 29 Junior Poster

Try this....

Dim i As Integer
i = DataGridView1.CurrentRow.Index
'then use the insert query with the parameters like 

DataGridView1.Item(0, i).Value 'cell value keeps on changing for all cells
poojavb 29 Junior Poster

First declare the variables and then when u will use the select query make use of reader that will read the value and assign it to the variable

eg

Dim docid as String
Dim docfname as String
Dim doclname as String
'connection string
Try
    Dim myCommand As OleDbCommand
    myCommand = New OleDbCommand("SELECT DoctorID,FirstName,LastName FROM DoctorRegister", Connection)
    Dim reader As OleDbDataReader = myCommand.ExecuteReader
    While reader.Read
          docid = reader("DoctorID")
          docfname = reader("FirstName")
          doclname = reader("LastName")
    End While
    reader.Close()
 Catch ex As Exception
    MsgBox("Error Connecting to Database: " & ex.Message)
End Try

Hope this helps u....

poojavb 29 Junior Poster

what does the searchdatas() function do??? it is not mentioned in the code???

try to write the below code in Textbox change event rather than button click and see

open connection first

         Try

            Dim myCommand As New SqlCommand
            With myCommand
                .CommandText = "SELECT * FROM tablename where columnid like '" & Textbox2.Text & "%" + "'"
                .CommandType = CommandType.Text
                .Connection = Connection
            End With
            Dim dt As New DataTable
            dt.Load(myCommand.ExecuteReader)
            With PelangganDataGridView
                .AutoGenerateColumns = True
                .DataSource = dt
            End With
        Catch ex As Exception
            Debug.Print("Exception: ")
            Throw ex
        End Try

check this or put the code in ur button click

poojavb 29 Junior Poster

first there shud be an insert query to move ur records to the other table and then an update query

eg.insert into newtablename(col1, col2, col3) select col1,col2,col3 from oldtablename

and then an update query based on userid

update oldtablename set count=value1,times=value2 where user_id="STEVE20"

hope it helps u

poojavb 29 Junior Poster
Process.Start("exeprocessname","filename")

eg. Process.Start("Notepad.exe","C:\text.txt")

poojavb 29 Junior Poster

This worked fine

Dim date_now As Date
date_now = DateTime.Now
Debug.Print(date_now.ToString("yyyy/MM/dd HH:mm:ss"))
poojavb 29 Junior Poster

When I added ur block of comment in eclipse and tried to execute it ...it showed a lot of errors for variables like total_ot_income is not resolved and many so on.....One closing brace bracket is missing at the end also...try to paste the complete code again and also the error msgs....and what;s in ur text file the employee info??

poojavb 29 Junior Poster

What kind of database is it?? Access, MSSQL or MYSQL?

I derived a query in Access
hope ur colname is a datetime field

SELECT *
FROM tablename
WHERE (format(colname,"yyyy")<Year(Now())-4);
poojavb 29 Junior Poster
Dim di As New IO.DirectoryInfo("Your directory path")
                    Debug.Print("di: " + di.ToString)
                    Dim diar1 As IO.FileInfo() = di.GetFiles()
                    Dim dra As IO.FileInfo
                    'list the names of all files in the specified directory
                    For Each dra In diar1
                        lstFiles.Items.Add(dra) 'all files present in the directory are viewed in list box
                    Next

hope it helps u...

Jx_Man commented: VB.Net solution for VB6 ? -3
poojavb 29 Junior Poster

try using Date.Today instead of using My.Computer.Clock.LocalTime.Date

poojavb 29 Junior Poster

Remove that if (If ComboBox3.Text = "'") condition y u need it???

and u have written double quotes then single quote and then double quotes in the if condition for combobox text....y u need that??? remove the single quote and keep it just If ComboBox3.Text = "" Then....i would recommend to remove that condition

anyways if this is the condition it wont enter the if loop anytime...

poojavb 29 Junior Poster

paste ur code again so that we can help u....if already fixed mark the thread as solved....
Remove the if condition of validating...see if com is declared....check the connections

poojavb 29 Junior Poster

Use a list box instead of list view

before the code clear the list box every time else the value will be repeated...

use a distinct function in ur select query if the query is returning duplicate values

after the executer use a debug.Print("Query: "+ acscmd.CommandText) it will help u to understand the query

With ListBox1
            .DataSource = ds.Tables("TableName")
            .DisplayMember = "ColumnName"


        End With
poojavb 29 Junior Poster

Whenever u write a coding for Database connection use the try catch block

Try

' *ur complete code goes here * 

Catch ex as Exception
MsgBox(ex.Message) ' if u get an error in above coding it will be passed to catch block and will display the error
End try
poojavb 29 Junior Poster

use the below select query

"Select * from SchedulingTwos where YearLevels = '" & ComboBox1.Text & "'" and Sections = '" & ComboBox3.Text & '""

if this condition is true then u will get the alert message that the section is already added

poojavb 29 Junior Poster

What does ur combobox1 contains and what is in combobox3

Private Sub ComboBox3_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ComboBox3.Validating
    If ComboBox3.Validating Then
    con = New OleDbConnection("Provider= Microsoft.ACE.oledb.12.0; Data Source=C:\Users\edenzam\Desktop\CBFMNHS Enrollment System\CBFMNHS Enrollment System\bin\Debug\Enrollment System.accdb")
    Dim ewaaa As String = "Select * from SchedulingTwos where YearLevels = '" & ComboBox1.Text & "'"
    com = New OleDbCommand(ewaaa, con)
    con.Open()
    rid = com.ExecuteReader
        if rid.Read=True then
                MsgBox("Section Already Exist", MsgBoxStyle.Critical, "Error")
                ComboBox3.SelectedIndex = -1
        End If
    End If
End Sub
poojavb 29 Junior Poster

I build my project then I open the EXE file at the RELEASE FOLDER, when generating in a crystal report a error message pops up "LOAD REPORT FAILED".

Check the path for the crystal report or paste the crystal report code u have written

poojavb 29 Junior Poster

hello !
try this may be this will solve your prob

dim con as new sqlconnection("connectionstring")
con.open()
dim da as new sqldataadapter("select firstname,lastname,address from table where firstname='" +txtfirstname.text+"' and lastname='"+txtlastname.text +"' and address='"+ txtaddress.text+"'",con)
dim dt as new datatable
da.fill(dt)
if dt.rows.count = 0 then
'means record is not in db , you can save
else
'record is already in db , so dont save
end if

this is not the ideal solution as i think this thing make your program slow ,but it will solve your prob .
if your prob is solved then please mark this thread solved .

Regards

U can also use a datareader instead of datatable....

if the reader returns true means the data is present so do not insert....else insert

Try
                Dim myCommand As OleDbCommand
                myCommand = New OleDbCommand("your sql query", Connection)
                Dim reader As OleDbDataReader = myCommand.ExecuteReader
                if reader.read=True
                 MsgBox("Data already exists")
                else
                 'insert the data
                reader.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
marcmanlin2 commented: thanks i got it. +0
poojavb 29 Junior Poster

i am so confuse dude..

why in my visual studio 2010 ultimate didn't show crystal report gallery?

after i click "add new item" and add crystal report, it just show me SAP page that say "learn and download".
i have install SAP crystal report runtime engine for .NET framework 4(32-bit).

i'm new to this thing, please guide me dude :(

thanks in advance..

Crystal report runtime is usefull in runtime not for creating crystal reports...

u need to install the crystal reports exe file first so that u will be able to create reports...when u install the crystal report software u will also get the runtime installer with it....

Download the 288MB package from the link learn and download and install it...

poojavb 29 Junior Poster

Hello,

currently, what i want to do is, add a column in a table "default" during runtime. Well, I've got that covered already.

The problem is, the column names are actually taken from the users input through a textbox or drop down list and of course, if the same column is added already in the table, it generates an error since it has to be unique.


That is why i wonder if it is possible to know if a column already exists without viewing the form which contains the grid view of that table?


Thanks if you can help :$

What u can do is....

before inserting the value into database u need to check if the value exists in the table
using the select query

"select colname from tablename where colname="'+textbox1.text+"'"

If the reader returns a true value then u shid not save the value in the database instead show a msg box that value already exists...

else save the value in database....

hope it helps u...

for eg...

Try
             Dim myCommand As SqlCommand
            myCommand = New SqlCommand("select  colname from tablename where colname='" + Textbox1.Text + "'", Connection)
            Dim reader As SqlDataReader= myCommand.ExecuteReader
            If reader.Read = True Then
              MsgBox("Input already exists")
            Else
               'Save query goes here
            End If
            reader.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

u can also add the distinct keyword in the select query.... and also u can code for ignore case

poojavb 29 Junior Poster

Yes...

DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy - HH:mm:ss");

But how do I include the miliseconds (and the localized version of the day of the week)?

Check this

Dim MyTime As String
MyTime = DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss.fff")

It gives the output:
09-Feb-2012 18:08:14.403

Sorry its in vb.net

poojavb 29 Junior Poster

Okay, I implemented the changes that you suggested, and VS 2010 now tells me that it is expecting an end of statement at the

combobox3.text & "'"

I don't understand what it means.....

This is the update Query with the changes in it

Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "'" & "and where [Board Size] = " & "'" ComboBox3.Text & "'"

No need to add the where twice

Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "' and  [Board Size] = '" & ComboBox3.Text & "'"

This will help u

poojavb 29 Junior Poster

im a beginner wid vb .net and need to clear the air wid connecting a database file created on sql server 2008r2 wid vb.net 2008 for a project..plz nebody help from scratch regardng retriving,insertng n modifyng data using vb.net code..awaiting....

u can create a module and call it every time u need a connection

Imports System.Data.SqlClient

Module DBConnection
    Public Connection As SqlConnection = New SqlConnection()
    Public Function Open_DB_Connection() As String
        Try
            Connection.ConnectionString = "Server=.\SQLEXPRESS;" & _
                    "Database=DBName;Trusted_Connection=True"
            Connection.Open()
            Return "Success"
        Catch ex As Exception
            Debug.Print(ex.Message & "in DBConnection_Module")
            Return "Fail"
            Exit Function
        End Try
    End Function

    Public Function Close_DB_Connection() As String
        Try
            Connection.Close()
            Return "Success"
        Catch ex As Exception
            Debug.Print(ex.Message & "in DBConnection_Module")
            Return "Fail"
            Exit Function
        End Try
    End Function
End Module

calling DB connection in ur forms

Dim Open_DB_Con As String
Open_DB_Con = Open_DB_Connection()

--your SQl query part goes here

Dim Close_DB_Con As String
Close_DB_Con = Close_DB_Connection()
poojavb 29 Junior Poster

U can try this too for a alphanumeric or if u need only numeric increment then delete the red part

Try
            Dim myCommand As SqlCommand
            Dim STid As String
            myCommand = New SqlCommand("select ISNULL(Max(SUBSTRING(id,4,7)),0) From Studentreg", Connection)
            Dim reader As SqlDataReader = myCommand.ExecuteReader
            reader.Read()
            STid= reader.Item(0) + 1
            Textbox1.Text = "ST" +  STid.ToString()
            reader.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

use this for numeric increment...the datatype in database should be an integer

Try
            Dim myCommand As SqlCommand
            Dim STid As String
            myCommand = New SqlCommand("select MAX(ID) From Studentreg", Connection)
            Dim reader As SqlDataReader = myCommand.ExecuteReader
            reader.Read()
            STid= reader.Item(0) + 1
            Textbox1.Text = STid.ToString()
            reader.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
poojavb 29 Junior Poster

Have you tried the .ToString() function?

Example...

TxtRate.Text = dt.Rows(0).Item(1).ToString

Try this...

Dim conn As New SqlConnection(ConnectionString)
        Dim abc As String
        abc= cbMenu.Text 'the value selected in combo box       
        Dim strSQL As String = "select Menu_Rate from Menu where Menu_Name='" & abc & "'"
        Dim da As New SqlDataAdapter(strSQL, conn)
        Dim ds As New DataSet
        da.Fill(ds, "Menu")
        With txtRate ' your text box name
            .DataSource = ds.Tables("Menu") 'your table name            
            .DisplayMember = "Menu_Rate"
          '  .ValueMember = "ProductID"
        End With