A Data Grid Issue ...

  • Thread starter Thread starter Nesho
  • Start date Start date
N

Nesho

Hi to all the ADO.NET developers. I have a simple
question : Is there a way to choose which columns in the
data grid that is bound to a data table are to be
visible ? I want to hide some columns that I use only for
setting a data relation with another data table. Thanks.
 
The trick is to not let the DataGrid autogenerate the
columns. DataGrid.TableStyles is the trick. If you are
using the designer, it is really easy. Create a new
TableStyle and change the TableStyle's ColumnCollection.
If you are using a Typed DataSet you can actually get it
to auto-fill the columns and let you edit them.

HTH

Thanks,

Shawn Wildermuth
(e-mail address removed)
Author of Pragmatic ADO.NET
http://adoguy.com/book
http://ONDotnet.com
 
Is the error I am getting when updating. Where a, I going wrong, this is
driving me nuts

Sub add_Person(Optional ByVal frmNewPerson As frmPerson = Nothing)

'Debug.WriteLine("add_Person")

Dim DR As DataRow

Dim InsertCmd As New OleDbCommand

'Open the connection

con.Open()

'Set up the insert command

InsertCmd.CommandType = CommandType.Text

InsertCmd.CommandText = "INSERT INTO [People]([Address1], [Address2],
[Address3], [Address4], [Country], [County], [DOB], " & _

", [FirstName], [Home Phone], [LastName], [MiddleInnitial], [Mobile
Fone], [Post Code]," & _

"[Town]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

InsertCmd.Connection = con

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Address1",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address1"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Address2",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address2"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Address3",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address3"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Address4",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address4"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Country",
System.Data.OleDb.OleDbType.VarWChar, 50, "Country"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("County",
System.Data.OleDb.OleDbType.VarWChar, 50, "County"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("DOB",
System.Data.OleDb.OleDbType.DBDate, 0, "DOB"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Email",
System.Data.OleDb.OleDbType.VarWChar, 50, "Email"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("FirstName",
System.Data.OleDb.OleDbType.VarWChar, 20, "FirstName"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Home_Phone",
System.Data.OleDb.OleDbType.VarWChar, 50, "Home Phone"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("LastName",
System.Data.OleDb.OleDbType.VarWChar, 20, "LastName"))

InsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("MiddleInnitial",
System.Data.OleDb.OleDbType.VarWChar, 3, "MiddleInnitial"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Mobile_Fone",
System.Data.OleDb.OleDbType.VarWChar, 50, "Mobile Fone"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Post_Code",
System.Data.OleDb.OleDbType.VarWChar, 10, "Post Code"))

InsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Town",
System.Data.OleDb.OleDbType.VarWChar, 50, "Town"))

'

daPeople.InsertCommand = InsertCmd



'Genereate New Row

DR = tablePeople.NewRow()

DR("FirstName") = frmNewPerson.txtFirstName.Text

DR("LastName") = frmNewPerson.txtLastName.Text

DR("DOB") = frmNewPerson.txtDOB.Text

DR("Home Phone") = frmNewPerson.txtHomeFone.Text

DR("Mobile Fone") = frmNewPerson.txtMobileFone.Text

DR("Email") = frmNewPerson.txtEmail.Text

DR("Address1") = frmNewPerson.txtAddress1.Text

DR("Address2") = frmNewPerson.txtAddress2.Text

DR("Address3") = frmNewPerson.txtAddress3.Text

DR("Address4") = frmNewPerson.txtAddress4.Text

DR("Town") = frmNewPerson.txtTown.Text

DR("County") = frmNewPerson.txtCounty.Text

DR("Post Code") = frmNewPerson.txtPostCode.Text

DR("Country") = frmNewPerson.txtCountry.Text

DR("MiddleInnitial") = ""

tablePeople.Rows.Add(DR)

Try

daEvents.Update(tablePeople)

Catch ex As OleDbException

MessageBox.Show(ex.Message())

End Try

tablePeople.Clear()

daPeople.Fill(tableEvents)

tablePeople.AcceptChanges()

'Close the connection

con.Close()



--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
 
sorry for posting at this thread level

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
One Handed Man said:
Is the error I am getting when updating. Where a, I going wrong, this is
driving me nuts

Sub add_Person(Optional ByVal frmNewPerson As frmPerson = Nothing)

'Debug.WriteLine("add_Person")

Dim DR As DataRow

Dim InsertCmd As New OleDbCommand

'Open the connection

con.Open()

'Set up the insert command

InsertCmd.CommandType = CommandType.Text

InsertCmd.CommandText = "INSERT INTO [People]([Address1], [Address2],
[Address3], [Address4], [Country], [County], [DOB], " & _

"(e-mail address removed)
 
Thank you, it was helpful.
p.s. The trick is also not to forget to set appropriate
mapping to the table style, as i did. :-)
 
Back
Top