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

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

Related

how to hide other column

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

loading data in bulk into a postgreSQL table that has a ForeignKey using SQLAlchemy

I have the following code in PostgreSQL/SQLAlchemy.
def load_books():
with open('C:\\Users\\books_raw.csv', 'r') as file:
for line in file.readlines():
record = line.split('$') # split at delimiter
book_isbn = record[0].strip('"')
book_title = record[1]
book_authors = record[2]
book_avg_rating = record[2]
book_format = record[4]
book_img_url = record[5]
book_num_pages = record[6]
book_pub_date = record[7]
book_publisher = record[8].strip() # ESTABLISH RELATIONSHIP
book = Books(title=book_title, isbn=book_isbn, authors=book_authors, avg_rating=book_avg_rating, format=book_format,
img_url=book_img_url, num_pages=book_num_pages, pub_date=book_pub_date, publisher=Publication(name=book_publisher))
session.add(book)
session.commit()
count = session.query(Books).count()
print(count, ' books added to the database')
My problem was with the relationship. If you see this part of the code:
publisher=Publication(name=book_publisher))
here i don't want the record to be inserted into the table, but just establish a relation with an existing record in the main table. Any ideas how i can achieve this ?
In for loop check if publisher in db or not if not in db then can create new one and save book with this publisher:
for line in file.readlines():
...
publisher=Publication.query.filter(name=book_publisher).first()
if not publisher:
publisher=Publication(name=book_publisher)
book = Books(..., publisher=publisher)
r = session.query(Publication).filter(Publication.name == book_publisher).first()
book = Books(title=book_title, isbn=book_isbn, authors=book_authors, avg_rating=book_avg_rating, format=book_format,
img_url=book_img_url, num_pages=book_num_pages, pub_date=book_pub_date, pub_id=r.id)
session.add(book)

Open a Globally Defined Database by ReplicaID in a LotusScript Class

I have a LS Class in as Library and the class works fine except now I need to open the database by replicaID. I have done this in other cases in an LS Library using the method below but the line :
Dim tDB As New NotesDatabase(serverName , LogRepID)
Does not actually open the database so when I set the Global logDB = tDB it is not opened and the script fails. LogRepID is the correct Replica ID and I did essentially the same open process in a simple LS Library without problems.
Class AgentLog
AutoSave As Integer
Enabled As Integer
LogDoc As NotesDocument
LogItem As NotesRichTextItem
LogDB As NotesDatabase
LogRepID As String
LogStyle As NotesRichTextStyle
DefaultStyle As NotesRichTextStyle
ViewIcon As Integer
Errors As Integer
mainDB As NotesDatabase
serverName As String
vwApplication As NotesView
appDoc As NotesDocument
Sub New(Process As String, pAutoSave, pEnabled)
Enabled = Cint(pEnabled)
If Enabled Then
Dim S As New NotesSession
Set mainDB = S.CurrentDatabase
serverName = mainDB.Server
Set vwApplication = mainDB.getView("vwWFSApplicationsEnabled")
Set appDoc = vwApplication.Getdocumentbykey("Admin", True)
LogRepID = appDoc.Getitemvalue("agentLogRepID")(0)
Dim tDB As New NotesDatabase(serverName , LogRepID)
Set LogDB = tDB
If LogDB.IsOpen Then
Set LogDoc = LogDB.CreateDocument()
Call LogDoc.ReplaceItemValue("Form", "frmWFSAgentLog")
Solution:
Changed the code to:
Dim tDB As New NotesDatabase("" , "")
tDB.Openbyreplicaid ServerName , LogRepID
Set LogDB = tDB
and now it works not sure if this is the best way, but it works.
This is the right way to go. Take a look at the example from the help of the Domino Designer:
Dim db As New NotesDatabase( "", "" )
If db.OpenByReplicaID( "Moscow", "85255FA900747B84" ) Then
Print( db.Title & " was successfully opened" )
Else
Print( "Unable to open database" )
End If

VB.NET Chart is not updating when dataset updates

I have a sub called addchartPrevious24()
This sub is being called on the initial load and when the user calls for a refresh. The job of this sub is to go out to an access database query the information. Populate into a dataset. Then create a chart and chart area. The dataset is then set as the datasource of the chart. My issue is if i reexecute the sub it does not update the chart with the new data although the dataset does get updated.
Public Sub addchartPrevious24()
Dim Connection As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\manage.mdb;Jet OLEDB:Database Password=password")
Dim da1 As New OleDb.OleDbDataAdapter
Dim ds1 As New DataSet()
Dim Command As New OleDb.OleDbCommand
Connection.Open()
da1.SelectCommand = New OleDb.OleDbCommand("SELECT General_Counters_Table.product_id, Sum(General_Counters_Table.ulboardcyclecount) AS SumOfulboardcyclecount, ltrim(STR(Month(General_Counters_Table.Date_Time)))+ '/'+Ltrim(STR(Day(General_Counters_Table.Date_Time))) + '/'+ltrim(STR(Year(General_Counters_Table.Date_Time))) + ' hour ' +Ltrim(STR(Hour(General_Counters_Table.Date_Time))) as DATEConverted FROM General_Counters_Table where Date_Time >=(NOW()-1) and Date_Time <= (NOW()) GROUP BY General_Counters_Table.product_id, Year(General_Counters_Table.Date_Time), Month(General_Counters_Table.Date_Time), Day(General_Counters_Table.Date_Time), Hour(General_Counters_Table.Date_Time) ORDER BY Year(General_Counters_Table.Date_Time), Month(General_Counters_Table.Date_Time), Day(General_Counters_Table.Date_Time), Hour(General_Counters_Table.Date_Time)", Connection)
da1.Fill(ds1, "Throughput")
Connection.Close()
'Defines Chart and Chart Area
Dim chart1 = New Chart()
Dim chartarea1 As ChartArea = New ChartArea()
TabPage2.Controls.Add(chart1)
chartarea1.Name = "ChartArea1"
chart1.ChartAreas.Add(chartarea1)
Chart1.Location = New System.Drawing.Point(10, 10)
chart1.Name = "Chart1"
Chart1.Size = New System.Drawing.Size(800, 400)
chart1.TabIndex = 0
chart1.Text = "Chart1"
chartarea1.AxisX.LabelStyle.Angle = -60
chartarea1.AxisX.Interval = 1
chartarea1.AxisY.MajorGrid.Interval = 5
chartarea1.BackColor = Color.Azure
chartarea1.ShadowColor = Color.Red
chartarea1.Area3DStyle.Enable3D = True
chartarea1.AxisX.MajorGrid.Enabled = False
chartarea1.AxisX.LabelStyle.Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Italic)
'Legend
Dim legend1 As Legend = New Legend()
legend1.Name = "Legend1"
chart1.Legends.Add(legend1)
'Series
Dim series1 As Series = New Series()
series1.ChartType = SeriesChartType.StackedColumn
series1.ChartArea = "ChartArea1"
series1.Legend = "Legend1"
series1.Name = "Throughput"
chart1.Series.Add(series1)
chart1.Series("Throughput").XValueMember = "DateConverted"
chart1.Series("Throughput").YValueMembers = "sumofulboardcyclecount"
chart1.Series("Throughput").IsValueShownAsLabel = True 'shows label on datapoint
chart1.DataSource = ds1.Tables("Throughput")
chart1.Update()
chart1.DataBind()
End Sub
I had the same problem, a resolution is presented for "This Question"
Try clearing your data points using:
Chart.Series.Points.Clear()
and then adding them again.

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.