|
hi guys,
can somebody help me and show me codes on how to save changes(in information) in datagridview connected to an SQL database. I was looking for codes ever since, but it doesn't work as i expected it to be.
I'm a beginner here, so I'm having a hard time creating the codes with datagridview.
Here's how it should work. I have DataSet1 and DataGridView1. When I run the program, i could add row/record to the datagridview, or edit, or delete record/s and save it onto the SQL database.
Hope anyone could help me here.
Thanks..;)
angeldeity
|
|
|
|
|
Abbhie wrote: can somebody help me and show me codes on how to save changes(in information) in datagridview connected to an SQL database. I was looking for codes ever since, but it doesn't work as i expected it to be.
I'm a beginner here, so I'm having a hard time creating the codes with datagridview.
Here is an example of how you can accomplish something like this:
Create two forms, call them Form1 and Form2. Put a DataGridView (DataGridView1) and a button (btnUpdateRow) on Form1. Create 3 textboxes on Form2 and call them txtId, txtFirstName and txtLastName.
Creating a sample dataset with 3 rows of data:
Public Table1 As DataTable<br />
<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Table1 = New DataTable("People")<br />
Dim Row1, Row2, Row3 As DataRow<br />
<br />
Try<br />
Dim Id As DataColumn = New DataColumn("Id")<br />
Id.DataType = System.Type.GetType("System.Int32")<br />
Table1.Columns.Add(Id)<br />
<br />
Dim FirstName As DataColumn = New DataColumn("First Name")<br />
FirstName.DataType = System.Type.GetType("System.String")<br />
Table1.Columns.Add(FirstName)<br />
Dim LastName As DataColumn = New DataColumn("Last Name")<br />
LastName.DataType = System.Type.GetType("System.String")<br />
Table1.Columns.Add(LastName)<br />
<br />
Row1 = Table1.NewRow()<br />
Row1.Item("Id") = 1<br />
Row1.Item("First Name") = "Pete"<br />
Row1.Item("Last Name") = "Soheil"<br />
Table1.Rows.Add(Row1)<br />
<br />
Row2 = Table1.NewRow()<br />
Row2.Item("Id") = 2<br />
Row2.Item("First Name") = "Bill"<br />
Row2.Item("Last Name") = "Gates"<br />
Table1.Rows.Add(Row2)<br />
<br />
Row3 = Table1.NewRow()<br />
Row3.Item("Id") = 3<br />
Row3.Item("First Name") = "George"<br />
Row3.Item("Last Name") = "Washington"<br />
Table1.Rows.Add(Row3)<br />
<br />
DataGridView1.DataSource = Table1<br />
Catch ex As Exception<br />
MessageBox.Show("Error: " & ex.Message)<br />
End Try<br />
<br />
End Sub<br />
Code to call the update Form2 and allow you to change row values:
Private Sub btnUpdateRow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateRow.Click<br />
Dim SelectedRowIndex As Integer<br />
Dim SelectedRowCount As Integer = DataGridView1.SelectedRows.Count<br />
<br />
If DataGridView1.SelectedRows Is Nothing Then<br />
MessageBox.Show("Please Select a Row")<br />
Exit Sub<br />
End If<br />
<br />
If SelectedRowCount < 1 OrElse SelectedRowCount > 1 Then<br />
MessageBox.Show("Invalid Row Selection.")<br />
Exit Sub<br />
End If<br />
<br />
Dim SelectedRow As DataGridViewRow = DataGridView1.SelectedRows.Item(0)<br />
SelectedRowIndex = SelectedRow.Index<br />
<br />
Dim f As New Form2<br />
<br />
f.txtId.Text = SelectedRow.Cells(0).Value<br />
f.txtFirstName.Text = SelectedRow.Cells(1).Value<br />
f.txtLastName.Text = SelectedRow.Cells(2).Value<br />
f.ShowDialog()<br />
<br />
DataGridView1.Rows.Item(SelectedRowIndex).Cells(0).Value = f.txtId.Text<br />
DataGridView1.Rows.Item(SelectedRowIndex).Cells(1).Value = f.txtFirstName.Text<br />
DataGridView1.Rows.Item(SelectedRowIndex).Cells(2).Value = f.txtLastName.Text<br />
End Sub
I used a DataTable for my example, but if you want to use a dataset instead all you have to do is to add the datatable to a dataset and you are good to go.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
|
thanks for the reply.. i'll try these codes..
|
|
|
|
|
i have a simple doubt but i dont know how to do it..
actually i have displayed a database table in datagrid....
now i want to add or delete some values of data grid for dat i have given an edit button which opens a new form wid column name in labels and their values to be enterd in textboxes....
i want wen i click update button values get update with original datagrid window still opened..
database coding is not the deal..
important part is how can i update values of one form while focus on other form...
thanks in advance....
|
|
|
|
|
hi friends,
i'm new to reporting in win app.. so i need a great help.. my problem is..
i want to show a report that populate data from two tables. & i used the sql query like this.
dim _Ssql as string=""
_Ssql="Select d1.id, d1.name, c1.name from Dress d1, Color c1 where " _
& " c1.id=d1.c and d1.id=10 "
Hope u got my query...
i'm using the sql server , so i created a crystal report and add the fields from the two tables. now i used the below code to show the report
dim objds as new Dataset
dim _Cconnect as new GetConnection
objds=_Cconnect.GetAll(ssql)
dim crt as new Report1
crt.setDatasource(objds)
CrystalReportViewer1.ReportSource=crt
The main problem is when show the report it displays all the records.. but its not taking the data from dataset. ie it should show only 1 record.. How can i resolve this...
cheers...
|
|
|
|
|
need help.. How can I display the item or the currentcell that I doubleclickd in the datagridview in a textbox.. can somebody send me a code for that.. or how can I show the form displaying the details of the current cell I doubleclickd.
I have a project that is an inventory system.In my database I have a table called ComputerUnits, the fields are serialNo, itemDescription, itemCategory, dateAcquired,etc. I displayed all the serialNo's from my database in a datagridview. The problem is, how to display the information of a specific serialNo in a another form by doublecliking that serialNo in the datagridview. I'm just a beginner so pls help...
im using win app..
tnx a lot
gt
|
|
|
|
|
Use the CellDoubleClick event handler. It will have an argument e , which is System.Windows.Forms.DataGridViewCellEventArgs type. From there, e.RowIndex will give you the row, and e.ColumnIndex will give you the column. I trust you can take it from there to fetch the data.
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
r u using win app or web app..
|
|
|
|
|
He didn't say in his original post. I assumed Windows app.
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
well, if it is Win app i used the code ..
Dim selected as DataGridCell
selected =DGlist.Currentcell
dim selectedItem as Object
selectedItem =DGlist.Item(selected.Rownumber,0)
Dim cellValue as integer
cellValue = CInt(selectedItem)
cheers....
|
|
|
|
|
hi
i want to know is it necessary to use printdialog,printpreview control for crystal report in vb.net2005? if yes then how it is use?
& one more question is that what is the difference between crystalpreview dialog control & printpreview ?
-- modified at 8:50 Sunday 30th September, 2007
Thanks
bye
|
|
|
|
|
I want to share some media files over LAN. I generated a list box which shows the list of files on my computer. I planned that when the user click on any filename mean when the listbox1 selectedindexchanged client computer automatically start VLC media player and start playing that file without asking any manual assistance from client.
I successfully generated file list on listbox1 which provide full path to the file when click on it mean ftp://server/media/filename.mp3
I use this code to activate the VLC media player
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim furl As String = "ftp://speedexbb/media/" & ListBox1.SelectedItem.ToString
With Process1
.StartInfo.FileName = My.Computer.FileSystem.CombinePath(My.Computer.FileSystem.SpecialDirectories.ProgramFiles, "videolan\vlc\vlc.exe")
.StartInfo.Arguments = furl
.Start()
End With
End Sub
Please help that is there anything wrong. as the VLC made error that unable to open file. how can i get ride of this.
I will be gratefull for kind support
miss Juliana
|
|
|
|
|
Have you tried launching the file, from the FTP server in VLC??
I'm willing the bet that VLC player can't play a file from an FTP server. In that case, you'd have to download the file to the local hard drive, then play the file from that.
|
|
|
|
|
Hi friends,
i'm new in windows application. can u please give me an idea about the crystal report generation. i searched lot but in confusion..different articles in different ways.. help me please
cheers..
|
|
|
|
|
otta patti illeda onnun paranju tharan....
|
|
|
|
|
When button is clicked it adds an image to picture box.
I need the image to have a number next to it or a rollover hint with the image name and number.
The problem is, when you add more than one of the same image you don't know which one was added first.
All images on 'The Grid' also get listed in a list box where I also need a number next to the name so it can be selected.
Any help is appreciated.
Thanks
|
|
|
|
|
I'm not sure what your question is really. Do you have a problem keeping track of the images in the program, or just with the method of showing the information?
---
single minded; short sighted; long gone;
|
|
|
|
|
OK, here is the situation. In the program I have a number of buttons, when you click on one an image is placed in a picture box which then can be moved and positioned on the screen. The image name is then listed in a list box. If you click another button another image is placed on the screen. If you go back and click the same button again the same image is place on the screen and is listed in the list box with the same name. Is there a way to add a number to the listbox picture name and have it correspond to the same item on the screen.
Thanks
|
|
|
|
|
Your best bet is to dispose of the picture boxes, and render a number on top of the images when you render them. Or, just load the image, build a graphics object, draw a number on it, and then put it in your wretched picture box.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Do you have any sample code on how to render a number on top of an image.
Thanks
|
|
|
|
|
Hi,
if you are already rendering the image, you can add text to it like so:
Graphics g=myPaintEventArgs.Graphics;
g.DrawImage(...);
g.DrawString(myText, myFont, ...);
But if you want to modify an image to include some text, get its graphics:
using (Graphics g=Graphics.FromImage(myImage)) {
g.DrawString(myText, myFont, ...);
}
myImage.Save(...);
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
This is the code for one of my buttons which places an image. Does it get added to this section?
Thanks
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim p As PictureBox
p = New PictureBox
Current_item = Item_names.door
p.Image = System.Drawing.Image.FromFile(door_image)
PictureBox1.Left = 84
PictureBox1.Top = 78
PictureBox1.Height = p.Image.Height
PictureBox1.Width = p.Image.Width
PictureBox1.Visible = True
PictureBox1.BorderStyle = BorderStyle.FixedSingle
PictureBox1.Image = System.Drawing.Image.FromFile(door_image)
PictureBox1.Select()
If PictureBox1.Controls.Count > 0 Then
PictureBox1.Controls.RemoveAt(0)
End If
p.Dispose()
End Sub
|
|
|
|
|
Hi Tom,
1.
my example code was C# not VB, sorry. VB.NET can do the same with a slightly different
syntax (except for the using statement, which is a shorthand for automatically calling
Dispose when done with an object).
2.
alternative one was about rendering, hence it goes in the Paint handler.
alterbative two was about modifying an existing image, hence it goes anywhere you like
(but such that it gets called only once for any given image)
3.
your code is a mess:
what is p and what is PictureBox1?? p is never really used/shown!
why would you set Top and Left again and again?
are you adding (and removing) Controls to a PictureBox???
4.
I am not exactly sure what it is you want to achieve, but
I concur with Cristian's suggestion to throw out all pictureboxes.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I have one data scraping project where my vb.net 2.0 application will browse pages and will extract information from there. The only problem is the IP address if the site comes to know that any IP is doing this job they block it. There are many softwares out there is in the market which hides the IP . Is there any way I can do this job in my application through code instead of buying any third party component ?
Any help would be precious
Best Regards
|
|
|
|
|
Do you understand what the purpose of an IP address is?
It allows servers to identify where the request for a page comes from and where to serve the results to.
This means that the server has to have an IP address supplied to it.
As far as I know all you can do is route yourself through a proxy server if you wish to hide your IP address.
You could write yourself a proxy server application - which is a task I am no expert in.
However that proxy server's IP address could get blocked.
You always pass failure on the way to success.
|
|
|
|