using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Order : Form
{
public int count = 0;
public string Conn = WindowsFormsApplication1.conn.getConnection();
public string getid;
public SqlDataAdapter dAdapter, dAdapter1;
public DataSet dSet, dSet1;
public SqlDataReader reader, reader1, reader2, myReader;
public int id, i;
public string mode;
public Order()
{
InitializeComponent();
}
private void Order_Load(object sender, EventArgs e)
{
SqlConnection myConnection_Company = new SqlConnection(Conn);
myConnection_Company.Open();
string load_company = "SELECT Customer_ID, Company_Name, Email FROM tbl_customer";
SqlCommand cmd_company = new SqlCommand(load_company, myConnection_Company);
SqlDataAdapter adapter_company = new SqlDataAdapter();
DataSet ds_company = new DataSet();
adapter_company.SelectCommand = cmd_company;
adapter_company.Fill(ds_company);
tb_Company.DataSource = ds_company.Tables[0];
tb_Company.ValueMember = "Customer_ID";
tb_Company.DisplayMember = "Company_Name";
tb_email.Text = ds_company.Tables["tbl_Customer"].Rows[0]["Email"].ToString();
reader = cmd_company.ExecuteReader();
myConnection_Company.Close();
}
private void tb_Company_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection myConnection_Company = new SqlConnection(Conn);
myConnection_Company.Open();
SqlDataAdapter adapter_company = new SqlDataAdapter("select * from tbl_Customer where Customer_ID='" + tb_Company.SelectedItem.ToString() + "'", myConnection_Company);
DataSet ds_company = new DataSet();
adapter_company.Fill(ds_company);
if (ds_company.Tables["tbl_Customer"].Rows.Count > 0)
{
tb_email.Text = ds_company.Tables["tbl_Customer"].Rows[0]["Email"].ToString();
}
else
{
tb_email.Text = "";
}
myConnection_Company.Close();
}
}
}
im also having this error message
---- object reference is not set to an instance
when i run this code
any help is very much appreciated :) thanks guys...
i want to add my dynamically created table rows.. to the database .. however i cant add it .. badly needed your help guys... thanks in advance
heres my code:
<?php
include('connect.php');
if(!isset($_SESSION['user_id']))
{
header('Location: login.php');
}
$user_id = $_SESSION['user_id'];
?>
<?php
$date = $_POST['date'];
if (isset($_POST['submit']))
{
if($date != '')
{
$desc = $_POST['desc'];
$unit = $_POST['unit'];
$qty = $_POST['qty'];
for ($i=0; $i<count($desc); $i++)
{
$ins_query = mysql_query("INSERT INTO t_request (`desc`) VALUES ('$desc [$i]')");
}
$afe = mysql_affected_rows();
if($afe > 0)
{
echo "<script>alert('Request Successfully Added')</script>";
echo "<script>window.location.replace('s_user_view.php')</script>";
}
else
{
echo mysql_error();
}
}
else
{
echo "<script>alert('Please Complete Details!')</script>";
echo "<script>window.location.replace('t_requisition.php')</script>";
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<?php include('head.php'); ?>
<link rel="stylesheet" type="text/css" media="all" href="jsdatepick-calendar/jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsdatepick-calendar/jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
window.onload = function(){
new JsDatePick({
useMode:2,
target:"inputField",
dateFormat:"%Y-%m-%d",
weekStartDay:0
});
new JsDatePick({
useMode:2,
target:"inputField2",
dateFormat:"%Y-%m-%d",
weekStartDay:0
});
};
</script>
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element1 = document.createElement("input");
element1.type = "text";
element1.name = "unit[]";
element1.style.border = "0px solid #000000";
cell2.appendChild(element1);
var cell3 = row.insertCell(2);
var element2 = document.createElement("input");
element2.type = "text";
element2.name = "desc[]";
element2.style.border = "0px solid #000000";
element2.size = "20";
cell3.appendChild(element2);
var cell4 = row.insertCell(3);
var element1 = document.createElement("input");
element1.type = "text";
element1.size = "10";
element1.name = "qty[]";
element1.style.border = "0px solid #000000";
cell4.appendChild(element1);
var cell5 = row.insertCell(4);
var element1 = document.createElement("input");
element1.type = "text";
element1.size = "10";
element1.name = "rec_qty[]";
element1.style.border = "0px solid #000000";
cell5.appendChild(element1);
var cell6 = row.insertCell(5);
var element1 = document.createElement("input");
element1.type = "text";
element1.name = "remarks[]";
element1.style.border = "0px solid #000000";
cell6.appendChild(element1);
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
</SCRIPT>
<style type="text/css" media="print">
@media print {
.displaycontrols {
display: none;
}
</style>
</head>
<body>
<!-- Start: Page Wrap -->
<div>
<!-- Header Grid Container: Start -->
<div class="grid_24" >
<?php include('header.php') ?>
<!-- Breadcrumb Bar: Start -->
<div id="breadcrumb">
<!-- Breadcrumb: Start -->
<ul class="left">
<li class="icon home"><a href="index.php" class="" title="Home">Home</a></li>
<!-- <li class="icon point_right"><a href="#">Dashboard</a></li> -->
</ul>
<!-- Breadcrumb: End -->
</div>
<!-- Breadcrumb Bar: End -->
<!-- *** START CODING HERE *** -->
<div class="grid_24" >
<!-- Box Header: Start --><!-- Box Header: End -->
<div class="box_top">
<h2 class="icon pages">Supply Requisition</h2>
</div>
<!-- Box Content: Start -->
<form method="post" class="form">
<div class="box_content padding">
<table width="800" border="2">
<tr>
<td colspan="3"><p align="center"><strong>REQUISITION AND ISSUE SLIP</strong><br />
<strong>Polytechnic University of the Philippines</strong></p></td>
</tr>
<tr>
<td width="300"><strong>Division: Commonwealth</strong></td>
<td width="308"><strong>Responsibilty Center RIS No.</strong></td>
<td width="279"><strong>Date:
<input type="text" name="date" id="inputField" style="border: 0px solid #000000;">
</strong></td>
</tr>
<tr>
<td><strong>Office:</strong></td>
<td><strong>Code:</strong></td>
<td><strong>Date:
</strong></td>
</tr>
<tr>
<td colspan="3"><strong><p align="center">Requisition
</p>
</strong></td>
</tr>
</table>
<table width="800" height="77" border="2" id="dataTable">
<tr>
<th width="100" scope="col"><strong>
<div class=displaycontrols>
<input type="button" value="+" onClick="addRow('dataTable')" />
<input type="button" onClick="deleteRow('dataTable')" value="-" />
</div>
</strong></th>
<th width="238" height="5" scope="col">Unit</th>
<th width="238" height="5" scope="col">Description</th>
<th width="238" height="5" scope="col">Quantity Units</th>
<th width="124" height="5" scope="col">Quantity</th>
<th width="253" height="5" scope="col">Remarks</th>
</tr>
<div id="tableID">
<tr valign="top">
<td><input type="checkbox" name="chk" id="checkbox"></td>
<td><input type="text" name="unit[]" id="unit" size="20" style="border: 0px solid #000000;"></td>
<td><input type="text" name="desc[]" id="desc" size="20" style="border: 0px solid #000000;"></td>
<td><input type="text" name="qty[]" id="qty" size="10" style="border: 0px solid #000000;"></td>
<td align="center"> </td>
<td align="center"><label>
<input name="remarks[]" type="text" id="remarks" size="20" style="border: 0px solid #000000;">
</label></td>
</div>
</tr>
</table>
<table width="800" border="2">
<tr>
<td height="5">Noted By:</td>
</tr>
<tr>
<td>Purpose:</td>
</tr>
</table>
<table width="800" border="2">
<tr>
<th width="97" scope="col"> </th>
<th width="164" scope="col">Requested by</th>
<th width="171" scope="col">Approve by</th>
<th width="167" scope="col">Issued by</th>
<th width="165" scope="col">Received by</th>
</tr>
<tr>
<td><strong>Signature:</strong></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><strong>Printed Name:</strong></td>
<td align="center"><input type="text" name="textfield" id="textfield" style="border: 0px solid #000000;"></td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"><input type="text" name="textfield4" id="textfield4" style="border: 0px solid #000000;"></td>
</tr>
<tr>
<td><strong>Designation:</strong></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<p>
<div class=displaycontrols>
<button name="submit" type="submit" class="field" id="submit" value="Submit">Submit</button>
</div>
</p>
</div>
</form>
</div>
<!-- Box Content: End -->
<!-- 100% Box Grid Container: End -->
<!-- *** END CODING HERE *** -->
<!-- Footer Grid: Start -->
<!-- Footer Grid: End -->
</div>
<!-- Footer Grid: End -->
</div>
<!-- End: Page Wrap -->
<!-- jQuery libs - Rest are found in the head section (at top) -->
<script type="text/javascript" src="js/jquery.visualize-tooltip.js"></script>
<script type="text/javascript" src="js/jquery-animate-css-rotate-scale.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.13.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.poshytip.min.js"></script>
<script type="text/javascript" src="js/jquery.quicksand.js"></script>
<script type="text/javascript" src="js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="js/jquery.facebox.js"></script>
<script type="text/javascript" src="js/jquery.uniform.min.js"></script>
<script type="text/javascript" src="js/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="js/syntaxHighlighter/shCore.js"></script>
<script type="text/javascript" src="js/syntaxHighlighter/shBrushXml.js"></script>
<script type="text/javascript" src="js/syntaxHighlighter/shBrushJScript.js"></script>
<script type="text/javascript" src="js/syntaxHighlighter/shBrushCss.js"></script>
<script type="text/javascript" src="js/syntaxHighlighter/shBrushPhp.js"></script>
<script type="text/javascript" src="js/fileTree/jqueryFileTree.js"></script> <!-- Added in 1.2 -->
<!-- jQuery Customization -->
<script type="text/javascript" src="js/custom.js"></script>
</body>
</html>
im trying to create view on ms sql having a primary key.. is that possible
is it possible to create a view with a primary key.. if so... how can i do that using a query of t sql.. anyone.. help..:?:
how can i pass a database value to a textbox if i click a button.. should i use a query statement..? what kind? help pls ...
so there's no way to put all the list in one row? because i want it to be on one row...
how can i pass mu multiple selecteditems from listbox to database...
i convert it to string however , the currently or last selected item is the only values being pass to the database..
string list = listbox1.SelectedItems.ToString();
i have a one datagridview textboxcolumn and i want the inpputted data form it to be pass into a column of my database does anyone here know what to do?
i want to create a table where i can input data in it when the form was runnig and when the button save was clicked it will pass the data being inputted .. to the sql server. what tool should i use to do such thing.
haha.. too funny i found out the answer to my question.. the code should go like this..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
namespace WindowsFormsApplication3pmp
{
public partial class MainForm : Form
{
DialogResult msgbox = new DialogResult();
public MainForm()
{
InitializeComponent();
}
private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
{
msgbox = MessageBox.Show("Are you sure you want to Log out?", "Log Out", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
{
if (msgbox == System.Windows.Forms.DialogResult.Yes)
{
this.Hide();
new LogIn ().Show();
}
else if (msgbox == System.Windows.Forms.DialogResult.No)
return;
}
}
}
}
can anyone help me...
the problem is that i want to hide a form when i click the button log out and show the log in form since you just log out and not close the form. but it does not happen...
here's my code...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
namespace WindowsFormsApplication3pmp
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult msgbox = new DialogResult();
MessageBox.Show("Are you sure you want to Log out?", "Log Out", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
{
if (msgbox == System.Windows.Forms.DialogResult.Yes)
{
this.Hide();
new LogIn ().Show();
}
else if (msgbox == System.Windows.Forms.DialogResult.No)
return;
}
}
}
}
i really appreciate ur help guys.. thanks..Mitja Bonca
i am a newbie so bare with me.. can anybody help me solve this prob.
input string was not in a correct format
this is my code... i can figure out what wrong with this ..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace WindowsFormsApplication3pmp
{
public partial class PayForm : Form
{
private ComboBox stype = new ComboBox();
private int paynosp, spAdd, payfpair;
public PayForm()
{
InitializeComponent();
}
private void Cancel_Click(object sender, EventArgs e)
{
this.Hide();
}
private void PaySrvcType_SelectedIndexChanged(object sender, EventArgs e)
{
stype.Items.Add("Baptismal");
stype.Items.Add("Special Baptismal");
stype.Items.Add("Confirmation");
stype.Items.Add("Communion");
SavePay.Click += SavePay_Click;
}
private void SavePay_Click(object sender, EventArgs e)
{
string noor = noOR.Text;
string paydate = PayDate.Value.ToShortDateString();
string payname = PayName.Text;
string stype = PaySrvcType.Text;
string stypeid = STypeID.Text;
string payfp = PayFP.Text;
string payNoSp = PayNoSp.Text;
string paytotal = payTotal.Text;
string addsp = Addsp.Text;
string AssessBy = assessBy.Text;
paynosp= Convert.ToInt32(payNoSp);
spAdd = Convert.ToInt32(addsp);
if (stype == "Baptismal")
{
stypeid += "1";
payfp += "200";
}
else if (stype == "Special Baptismal")
{
stypeid += "2";
payfp += "1000";
}
else if (stype == "Confirmation")
{
stypeid += "3";
payfp += "100";
}
payfpair = Convert.ToInt32(payfp);
paytotal += (payfpair +(paynosp * spAdd));
DialogResult msgbox = new DialogResult();
try
{
if (PayName.Text == "" || assessBy.Text == "" )
{
MessageBox.Show("There are still unanswered fields", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
// string adduser = String.Format(@"UPDATE INTO users_info (userID, Fname, Mname, Sname, Bdate, Position, username, password) VALUES (''{0}'',''{1}'', ''{2}'', ''{3}'',''{4}, ''{5}'', ''{6}'', ''{7}'')", UserID, userfname, usermname, usersname, userbdate, userpos, TBusername, TBpass);
const string connection = "Data source = abc; Database = PMP; Trusted_Connection = True;";
using (SqlConnection cnx = new SqlConnection(connection))
{
//SqlCommand command = new SqlCommand(adduser, cnx);
cnx.Open();
string addpay = (@"INSERT INTO table_OR ( ORdate, PayName, PayStypeId, PayStype, ORtotal, ORAsses)
VALUES ('" + paydate + "', '" +payname+ "', '" + stypeid + "', '" + stype + "', '" + paytotal + "','"+AssessBy+"')");
using (SqlCommand add_pay = new SqlCommand(addpay, cnx))
{
add_pay.ExecuteNonQuery();
}
MessageBox.Show("Payment successfully made!", "Successful!", MessageBoxButtons.OK);
// msgbox = MessageBox.Show("Edit another User?", "Edit Team", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (msgbox == System.Windows.Forms.DialogResult.Yes)
{
//text_reset();
PayName.Focus();
return;
}
else
this.Close();
cnx.Close();
}
}
}
catch (Exception err)
{
MessageBox.Show("Connection to database failed!" + err.Message);
//text_reset();
PayName.Focus();
return;
}
}
}
}