how to hide other column - mysql-workbench

In my datagridview, I just want to show other fields such as ID,LastName,FirstName, and MiddleName and i dont want to show any fields but i want it to retrieve even it's hidden. But when i specify what i just want to show in my datagridview it causes runtime error.
this is my code to load the datagridview.
MysqlConn.Open()
Dim Query As String
Query = "select ID,LastName,FirstName,MiddleName from god.precord"
COMMAND = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = COMMAND
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)
MysqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
then this is my code for retrieve data into textboxes
Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.RowIndex >= 0 Then
Dim row As DataGridViewRow
row = Me.DataGridView1.Rows(e.RowIndex)
txtid.Text = row.Cells("ID").Value.ToString
txtlastname.Text = row.Cells("LastName").Value.ToString
txtfirstname.Text = row.Cells("FirstName").Value.ToString
txtmiddlename.Text = row.Cells("MiddleName").Value.ToString
txtaddress.Text = row.Cells("Address").Value.ToString
txtcontactno.Text = row.Cells("ContactNo").Value.ToString
txtgender.Text = row.Cells("Gender").Value.ToString
dtpbirthdate.Text = row.Cells("Birthdate").Value.ToString
txtage.Text = row.Cells("Age").Value.ToString
End If
End Sub
runtime error
please help me this is for my thesis
thankyou in advance <3

You have to add hidden column into the select query to retreive the data.
Hide the column from the DataGridView instead.
try
MysqlConn.Open()
Dim Query As String
Query = "select ID,LastName,FirstName,MiddleName,Address from god.precord"
COMMAND = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = COMMAND
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)
DataGridView1.Columns("Address").Visible = false
MysqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try

Related

How to copy data from a form+sub-form to table in ms access?

I have created a form that has a subform attached. I have a button that runs a query to delete the record but first I want to copy the data from including all subform information if available to a table. I have used the following code but nothing happens. please! what am I have missing?
Private Sub Command63_Click()
Dim db As Database, delfile As Recordset, Criteria As String
Set db = CurrentDb
Set delfile = db.OpenRecordset("DelFile", DB_OPEN_DYNASET)
'add data to deleted taxpayer file table
With delfile
.AddNew
!DeletedBy = (Forms!MainMenu!username)
!Branch = Me.Branch
!TaxType = Me.TaxType
!Volume = Me.Volume
!Keyedby = Me.Keyedby
!DateKeyed = Me.DateKeyed
!CreatedAt = Me.CreatedAt
!Comment = Me.Comment
End With
delfile.Close
db.Close
End Sub
Once you have set all of your field values you need to include a .update for the changes to take affect. Your new code would look like this.
Private Sub Command63_Click()
Dim db As Database, delfile As Recordset, Criteria As String
Set db = CurrentDb
Set delfile = db.OpenRecordset("DelFile", DB_OPEN_DYNASET)
'add data to deleted taxpayer file table
With delfile
.AddNew
!DeletedBy = (Forms!MainMenu!username)
!Branch = Me.Branch
!TaxType = Me.TaxType
!Volume = Me.Volume
!Keyedby = Me.Keyedby
!DateKeyed = Me.DateKeyed
!CreatedAt = Me.CreatedAt
!Comment = Me.Comment
.Update
End With
delfile.Close
db.Close
End Sub

How do I add my shopping cart items to Transaction.item_list_.items

I am trying to pass over my shopping cart items to paypal using the .net REST API SDK
Below is the code:
Dim b As Integer = 0
Dim pCartItem As New PayPal.Api.Payments.Item
Dim pCartItemList As New PayPal.Api.Payments.ItemList
Do While b <= cart.Count - 1
pCartItem.name = cart(b).Name
pCartItem.price = cart(b).Price
pCartItem.quantity = cart(b).Quantity
pCartItem.currency = "USD"
pCartItem.sku = cart(b).Sku
pCartItemList.items.Add(pCartItem) 'This line errors out
pCartItem = New PayPal.Api.Payments.Item
b += 1
Loop
orderTransaction.item_list = pCartItemList
The line that errors out pCartItemList.items.Add(pCartItem) throws the error "Object reference not set to the instance of an object. Try using the keyword "new" :. I don't understand why because when i hover over the pCartItem in Visual Studio I am able to see all the correct values that have been assigned from my shopping cart.
Is this even the right way to add Item objects to the Transacation.item_list ?
Any help would be greatly appreciated.
Thanks,
Tommy
I have figured out that error for anyone else who may run into this here is the code that works
Dim pCartItem As PayPal.Api.Payments.Item = New PayPal.Api.Payments.Item
orderTransaction.item_list = New PayPal.Api.Payments.ItemList
orderTransaction.item_list.items = New List(Of PayPal.Api.Payments.Item)
Do While b <= cart.Count - 1
pCartItem.name = cart(b).Name
pCartItem.price = cart(b).Price
pCartItem.quantity = cart(b).Quantity
pCartItem.currency = "USD"
pCartItem.sku = cart(b).Sku
orderTransaction.item_list.items.Add(pCartItem)
pCartItem = New PayPal.Api.Payments.Item
b += 1
Loop

How can I convert U2 Business Logic Subroutine’s multi-value data into .NET Objects such as DataSet/DataTable using U2 Toolkit for .NET?

I have the following subroutine. It takes INPUT as argument 1 and sends multi-value data OUTPUT as argument 2.
SUBROUTINE MV_TO_DATASET_SELECT_SUBROUTINE(ARG_INPUT,ARG_OUTPUT)
x = ARG_INPUT
ARG_OUTPUT = "100":#VM:"101":#VM:"102":#VM:"103":#FM:"Nancy":#VM:"Andrew":#VM:"Janet":#VM:"Margaret":#FM:"01/06/1991":#VM:"06/07/1996":#VM:"11/08/1999":#VM:"12/10/2001"
RETURN
The Schema of above subroutine’s multi-value data is as below.
DataSet ds = new DataSet();
DataTable dt = new DataTable("Employee");
ds.Tables.Add(dt);
dt.Columns.Add("ID",typeof(Int32));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("HireDate", typeof(DateTime));
You can achevieve this task one of the following ways:
Use MV_To_DataTable() and DataTable_To_MV(). You can create schema of
subroutine by dragging and dropping Empty DataTable into Empty
DataSet Deginer.
By draagging and dropping Visual Studio Server Explorer’s U2
Subroutine into DataSet Designer. U2 Subrotine returns
resultset/dataset by executing API such as ST=SQLExecDirect(#HSTMT,
"SELECT F1 AS COL1,F2 AS COL2 ,F3 AS COL3 FROM #TMP SLIST 9 ORDER BY
1")
Use MV_To_DataTable() and DataTable_To_MV()
Create ASP.NET Web Application Project. Type ‘WebApplication_Subroutine’ in Project Name.
Add Reference to U2NETDK Assembly (U2.Data.Client)
Change header ‘Welcome to ASP.NET!’ to ‘Welcome to U2 Toolkit for .NET Demo on Business Logic Subroutine’s multi-value string data to .NET DataSet!’
Open ‘Default.aspx’ file and Go to Design Mode.
Do the following:
Drag and Drop Button Control. Name it ‘Load’
Drag and Drop Button Control. Name it ‘Update’
Drag and Drop GridView Control.
Right Click on Solution Explorer. Select Add ->New Item-DataSet. In the Name box, type ‘Employee.xsd’
Drag and Drop DataTable into Designer. Change the name to ‘Employee’ Table.
Create 3 new Columns (U2 subroutine Schema):
ID – DataType : INT
Name – DataType : STRING
HireDate - DataType : DATE
Open ‘Default.aspx’ file in Design Mode. Double Click ‘Load Button’. It will create Event handler Code behind.
Cut and paste the following code.
protected void Button1_Click(object sender, EventArgs e)
{
U2ConnectionStringBuilder l = new U2ConnectionStringBuilder();
l.Server = "127.0.0.1";
l.UserID = "user";
l.Password = "pass";
l.Database = "HS.SALES";
l.ServerType = "universe";
string lconnstr = l.ToString();
U2Connection c = new U2Connection();
c.ConnectionString = lconnstr;
c.Open();
U2Command command = c.CreateCommand();
command.CommandText = "CALL MV_TO_DATASET_SELECT_SUBROUTINE(?,?)";
command.CommandType = CommandType.StoredProcedure;
U2Parameter p1 = new U2Parameter();
p1.Direction = ParameterDirection.InputOutput;
p1.Value = "";
p1.ParameterName = "#arg_input";
command.Parameters.Add(p1);
U2Parameter p2 = new U2Parameter();
p2.Direction = ParameterDirection.InputOutput;
p2.Value = "";
p2.ParameterName = "#arg_output";
command.Parameters.Add(p2);
command.ExecuteNonQuery();
Employee.EmployeeDataTable dt = new Employee.EmployeeDataTable();
command.Parameters[1].MV_To_DataTable(dt);
Session["GridDataset"] = dt;
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
Run the application. Press ‘Load’ Button.
Open ‘Default.aspx’ file in Design Mode. Double click ‘Update Button’. It will create Event Handler in Code behind page.
Cut and Paste the following Code.
protected void Button2_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)Session["GridDataset"];
//To TEST, change first row
string s1 = (string)dt.Rows[0]["Name"];
dt.Rows[0]["Name"] = s1 + "NewValue";
// get the modified rows
DataTable dt_changed = dt.GetChanges();
//call DATASET_TO_MV_UPDATE_SUBROUTINE
U2ConnectionStringBuilder l = new U2ConnectionStringBuilder();
l.Server = "127.0.0.1";
l.UserID = "user";
l.Password = "pass";
l.Database = "HS.SALES";
l.ServerType = "universe";
string lconnstr = l.ToString();
U2Connection c = new U2Connection();
c.ConnectionString = lconnstr;
c.Open();
U2Command command = c.CreateCommand();
command.CommandText = "CALL DATASET_TO_MV_UPDATE_SUBROUTINE(?)";
command.CommandType = CommandType.StoredProcedure;
U2Parameter p1 = new U2Parameter();
p1.Value = "";
p1.Direction = ParameterDirection.InputOutput;
p1.ParameterName = "#arg_data";
command.Parameters.Add(p1);
command.Parameters[0].DataTable_To_MV(dt_changed);
// modified data going to subroutine
string lData = (string)command.Parameters[0].Value;
command.ExecuteNonQuery();
}
See the Modified Value in the Debugger when you click Update Button.
U2 Subrotine returns resultset/dataset
Create U2 Data Connection in Visual Studio Server Explorer. Expand Store Procedures Node.
Go to subroutine that returns resultset/dataset. Drag and Drop subroutine into DataSet Designer.
It shows INPUT argument and resultset/dataset columns.

Parameter to Crystal Report

i created a #Month as parameter name in crystal report and just insert to the report header section.
When i run the report always it asks the parameter by showing one box. How i pass through code. My existing code is below
MyReport rpt = new MyReport();
var srcData = ; //here i added my LINQ statement to select the data
rpt.SetDataSource(srcData);
ParameterDiscreteValue pdValue = new ParameterDiscreteValue();
pdValue.Value = combo2.SelectedValue;
rpt.ParameterFields["#Month"].CurrentValues.Add(pdValue);
this.ReportViewer1.ReportSource = rpt;
this.ReportViewer1.RefreshReport();
Where i did the mistake?
Hi I solved by just removing RefershReport() method of crystalreportviewer
I find from : http://www.it-sideways.com/2011/10/how-to-disable-parameter-prompt-for.html
If it's not working it suggests a typo or something. Try analyzing rpt.ParameterFields (set a breakpoint and watch). Have you got the parameter name correct? Data type?
I had trouble with adding parameters as well. Here's an example of what I got working:
string ponumber = Request.QueryString["ponumber"].ToString();
string receiptno = Request.QueryString["receiptno"].ToString();
// Put Away Report
CrystalReportSource CrystalReportSource1 = new CrystalReportSource();
CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();
CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.EnableParameterPrompt = false;
CrystalReportSource1.Report.FileName = "Report3.rpt";
CrystalReportSource1.EnableCaching = false;
// This will set the values of my two parameters in the report
CrystalReportSource1.ReportDocument.SetParameterValue(0, ponumber);
CrystalReportSource1.ReportDocument.SetParameterValue(1, receiptno);
TableLogOnInfo logOnInfo = new TableLogOnInfo();
logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["WarehouseReportServerName"];
logOnInfo.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["WarehouseReportDatabaseName"];
logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings["WarehouseReportUserID"];
logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings["WarehouseReportPassword"];
TableLogOnInfos infos = new TableLogOnInfos();
infos.Add(logOnInfo);
CrystalReportViewer1.LogOnInfo = infos;
maindiv.Controls.Add(CrystalReportSource1);
maindiv.Controls.Add(CrystalReportViewer1);
CrystalReportViewer1.DataBind();

Getting errors with Parameterized Update Sub

No idea why this isn't working.
I have a simple form with some text boxes and drop down lists. It displays the profile of an employee. Users should be able to manually edit the fields and click Save. When they click save I keep getting errors.
Q1: How can I handle inserting Null values for SmallDateTime data types?
Q2: What am I doing wrong with the TinyInt (SqlServer 2005) on the JobGrade?
Option Explicit On
Imports System
Imports System.Data
Imports System.Data.SqlClient
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim sqlJobsDB As New SqlConnection(ConfigurationManager.ConnectionStrings("JobsDB").ConnectionString)
Dim sqlCmdUpdate As SqlCommand = sqlJobsDB.CreateCommand()
Try
sqlJobsDB.Open()
sqlCmdUpdate.CommandText = _
"UPDATE tblEmployee " + _
"SET Firstname = #Firstname, LastName = #LastName, HiredLastName = #HiredLastName, " + _
"DateHired = #DateHired, Role = #Role, CADate = #CADate, CAType = #CAType, " + _
"JobDate = #JobDate, JobGrade = #JobGrade " + _
"WHERE EUID = '" & Session("sProfileEUID") & "';"
sqlCmdUpdate.Parameters.Add("#FirstName", SqlDbType.VarChar)
sqlCmdUpdate.Parameters.Add("#LastName", SqlDbType.VarChar)
sqlCmdUpdate.Parameters.Add("#HiredLastName", SqlDbType.VarChar)
sqlCmdUpdate.Parameters.Add("#DateHired", SqlDbType.SmallDateTime)
sqlCmdUpdate.Parameters.Add("#Role", SqlDbType.VarChar)
sqlCmdUpdate.Parameters.Add("#CADate", SqlDbType.SmallDateTime)
sqlCmdUpdate.Parameters.Add("#CAType", SqlDbType.VarChar)
sqlCmdUpdate.Parameters.Add("#JobDate", SqlDbType.SmallDateTime)
sqlCmdUpdate.Parameters.Add("#JobGrade", SqlDbType.TinyInt)
sqlCmdUpdate.Parameters("#FirstName").Value = txtFirstName.Text
sqlCmdUpdate.Parameters("#LastName").Value = txtLastName.Text
sqlCmdUpdate.Parameters("#HiredLastName").Value = txtHiredLastName.Text
sqlCmdUpdate.Parameters("#DateHired").Value = txtDateHired.Text
sqlCmdUpdate.Parameters("#Role").Value = ddlRole.SelectedValue.ToString
If txtCADate.Text = "" Then
sqlCmdUpdate.Parameters("#CADate").Value = 0
Else
sqlCmdUpdate.Parameters("#CADate").Value = txtCADate.Text
End If
sqlCmdUpdate.Parameters("#CAType").Value = ddlCAType.SelectedValue
If txtJobDate.Text = "" Then
sqlCmdUpdate.Parameters("#JobDate").Value = 0
Else
sqlCmdUpdate.Parameters("#JobDate").Value = txtJobDate.Text
End If
sqlCmdUpdate.Parameters("#JobGrade").Value = CByte(txtJobGrade.Text)
sqlCmdUpdate.ExecuteNonQuery()
Catch ex As Exception
'Debugging
lblErrMsg.Text = ex.ToString
lblErrMsg.Visible = True
Finally
sqlJobsDB.Close()
End Try
End Sub</code>
I open the form and fill it out correctly.
I'll enter something like "4" (no quotes) for JobGrade. It still says "conversion from strink ''" like its not even seeing when I input items on the form.
Errors are below:
System.InvalidCastException: Conversion from string "" to type 'Byte' is not valid. ---> System.FormatException: Input string was not in a correct format. at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToByte(String Value) --- End of inner exception stack trace --- at Microsoft.VisualBasic.CompilerServices.Conversions.ToByte(String Value) at Profile.btnSave_Click(Object sender, EventArgs e) in
Update
The DBNull.Value issue is resolved.
The JobGrade, and Role are still issues. When throwing up some breakpoints on it doens't fetch the contents of the textbox or the dropdown list.
** Updated Code **
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Session("sProfileEUID") = Nothing
Response.Redirect("~/Management/EditUsers.aspx")
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim sqlJobsDB As New SqlConnection(ConfigurationManager.ConnectionStrings("JobsDB").ConnectionString)
Dim sqlCmdUpdate As SqlCommand = sqlJobsDB.CreateCommand()
Try
sqlJobsDB.Open()
sqlCmdUpdate.CommandText = _
"UPDATE tblEmployee " + _
"SET FirstName = #FirstName, LastName = #LastName, HiredLastName = #HiredLastName, " + _
"DateHired = #DateHired, Role = #Role, CADate = #CADate, CAType = #CAType, " + _
"JobDate = #JobDate, JobGrade = #JobGrade " + _
"WHERE EUID = '" & Session("sProfileEUID") & "';"
sqlCmdUpdate.Parameters.Add("#FirstName", SqlDbType.VarChar)
sqlCmdUpdate.Parameters.Add("#LastName", SqlDbType.VarChar)
sqlCmdUpdate.Parameters.Add("#HiredLastName", SqlDbType.VarChar)
sqlCmdUpdate.Parameters.Add("#DateHired", SqlDbType.SmallDateTime)
sqlCmdUpdate.Parameters.Add("#Role", SqlDbType.VarChar)
sqlCmdUpdate.Parameters.Add("#CADate", SqlDbType.SmallDateTime)
sqlCmdUpdate.Parameters.Add("#CAType", SqlDbType.VarChar)
sqlCmdUpdate.Parameters.Add("#JobDate", SqlDbType.SmallDateTime)
sqlCmdUpdate.Parameters.Add("#JobGrade", SqlDbType.TinyInt)
sqlCmdUpdate.Parameters("#FirstName").Value = txtFirstName.Text
sqlCmdUpdate.Parameters("#LastName").Value = txtLastName.Text
sqlCmdUpdate.Parameters("#HiredLastName").Value = txtHiredLastName.Text
sqlCmdUpdate.Parameters("#DateHired").Value = txtDateHired.Text
sqlCmdUpdate.Parameters("#Role").Value = ddlRole.SelectedValue.ToString
If txtCADate.Text <> "" Then sqlCmdUpdate.Parameters("#CADate").Value = CDate(txtCADate.Text)
If txtCADate.Text = "" Then sqlCmdUpdate.Parameters("#CADate").Value = DBNull.Value
If ddlCAType.Text <> "" Then sqlCmdUpdate.Parameters("#CAType").Value = ddlCAType.SelectedValue
If ddlCAType.Text = "" Then sqlCmdUpdate.Parameters("#CAType").Value = DBNull.Value
If txtJobDate.Text <> "" Then sqlCmdUpdate.Parameters("#JobDate").Value = CDate(txtJobDate.Text)
If txtJobDate.Text = "" Then sqlCmdUpdate.Parameters("#JobDate").Value = DBNull.Value
If txtJobGrade.Text <> "" Then sqlCmdUpdate.Parameters("#JobGrade").Value = CInt(txtJobGrade.Text)
If txtJobGrade.Text = "" Then sqlCmdUpdate.Parameters("#JobGrade").Value = DBNull.Value
sqlCmdUpdate.ExecuteNonQuery()
Catch ex As Exception
lblErrMsg.Text = ex.ToString
lblErrMsg.Visible = True
Finally
sqlJobsDB.Close()
End Try
End Sub
Edit 2:
So I've pretty much given up on this, and instead moved the table into an FormView ItemTemplate, with an EditTemplate also. I modified it as described in the following link. http://www.beansoftware.com/ASP.NET-Tutorials/FormView-Control.aspx
Q1: Make sure the table structure allows nulls and set the parameter value to DBNull.Value.
Q2:
If IsNumeric(txtJobGrade.Text) Then
sqlCmdUpdate.Parameters("#JobGrade").Value = CInt(txtJobGrade.Text)
Else
sqlCmdUpdate.Parameters("#JobGrade").Value = 0 'Or Default Value
End If
You can always make that a drop down list to prevent open ended data input.
It's a little odd to see how you're done the parameters. Typically, I'd expect to see something more along these lines:
With sqlCmdUpdate.Parameters
.clear()
.addWithValue("#parm1", mytextbox1.text)
.addWithValue("#parm2", mytextbox2.text)
End With
For one, .add has been deprecated -- still works, but some issues to be aware of (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx).
Secondly, it's always best to call .clear().
Also -- you might think about a more standard approach to checking for values -- for example:
If txtJobGrade.Text <> "" Then...
Would be better written as
If NOT string.isnullorempty(me.txtJobGrade.text) Then...
Try making a few of those changes, and see what (if any) errors you're still getting.