I want to make value data from usercontrol will be save on database where the triggers is to click save button from other form. It should be a form that contain button save and usercontrol will be drag/put to that form.
My code us running without error, but the result in the database is not right.
Note: my code is running perfectly when I place save button on usercontrol but when I put save button on another form the result like on the image.
Code on form:
namespace REMAS.Forms.Account
{
public partial class frmCreateFixedAssetCategories : Form
{
SqlConnection conn = new SqlConnection("Server=localhost;Database=TESTCRUD;User Id=sa;Password=123456");
SqlCommand cmd;
SqlDataAdapter adapter;
SqlDataReader reader;
DataTable dt;
string sql, sAction;
int iID;
private uctInformation uctInformationInstance;
public frmCreateFixedAssetCategories()
{
InitializeComponent();
uctInformationInstance = new uctInformation();
// Assuming you have a panel or some container to host the UserControl
}
private void btnSaveActions_Click(object sender, EventArgs e)
{
uctInformationInstance.savedata();
}
}
}
code on usercontrol:
namespace REMAS.Forms.Purchase
{
public partial class uctInformation : UserControl
{
SqlConnection conn = new SqlConnection("Server=localhost;Database=TESTCRUD;User Id=sa;Password=123456");
SqlCommand cmd;
SqlDataAdapter adapter;
SqlDataReader reader;
DataTable dt;
string sql, sAction;
int iID;
public uctInformation()
{
InitializeComponent();
}
private void uctInformation_Load(object sender, EventArgs e)
{
ClearText();
}
void ClearText()
{
txbAddresses.Clear();
txbFixedPhone.Clear();
txbFaxuctInf.Clear();
txbMobileuctInf.Clear();
txbEmailuctInf.Clear();
txbWebuctInf.Clear();
txbRegCode.Clear();
txbTaxN.Clear();
txbLanguageuctInf.Clear();
txbAccOwner.Clear();
txbTeamuctInf.Clear();
cmbCategoryuctInf.Items.Clear();
cmbIndustryuctInf.Items.Clear();
cmbSourceuctInf.Items.Clear();
cmbDeptuctInf.Items.Clear();
cmbCompaniesAssoci.Items.Clear();
nudTurnoveructInf.Value = 0;
nudEmployeesuctInf.Value = 0;
nudPaymentuctInf.Value = 0;
rtbNotes.Clear();
}
private void txbFixedPhone_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !char.IsDigit(e.KeyChar) && e.KeyChar != (char)Keys.Back;
}
private void txbFaxuctInf_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !char.IsDigit(e.KeyChar) && e.KeyChar != (char)Keys.Back;
}
private void txbMobileuctInf_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !char.IsDigit(e.KeyChar) && e.KeyChar != (char)Keys.Back;
}
public void savedata()
{
try
{
if (conn.State == ConnectionState.Closed) conn.Open();
sql = "sp_InsertInformation";
cmd = new SqlCommand(sql, conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@addresses", txbAddresses.Texts.ToString());
cmd.Parameters.AddWithValue("@fixedphone", txbFixedPhone.Texts.ToString());
cmd.Parameters.AddWithValue("@fax", txbFaxuctInf.Texts.ToString());
cmd.Parameters.AddWithValue("@mobilephone", txbMobileuctInf.Texts.ToString());
cmd.Parameters.AddWithValue("@email", txbEmailuctInf.Texts.ToString());
cmd.Parameters.AddWithValue("@website", txbWebuctInf.Texts.ToString());
cmd.Parameters.AddWithValue("@category", cmbCategoryuctInf.Texts.ToString());
cmd.Parameters.AddWithValue("@industrisector", cmbIndustryuctInf.Texts.ToString());
cmd.Parameters.AddWithValue("@turnover", nudTurnoveructInf.Text.ToString());
cmd.Parameters.AddWithValue("@employee", nudEmployeesuctInf.Text.ToString());
cmd.Parameters.AddWithValue("@source", cmbSourceuctInf.Texts.ToString());
cmd.Parameters.AddWithValue("@deptdiv", cmbDeptuctInf.Texts.ToString());
cmd.Parameters.AddWithValue("@regcode", txbRegCode.Texts.ToString());
cmd.Parameters.AddWithValue("@taxn", txbTaxN.Texts.ToString());
cmd.Parameters.AddWithValue("@paymentdelay", nudPaymentuctInf.Text.ToString());
cmd.Parameters.AddWithValue("@lang", txbLanguageuctInf.Texts.ToString());
cmd.Parameters.AddWithValue("@accowner", txbAccOwner.Texts.ToString());
cmd.Parameters.AddWithValue("@team", txbTeamuctInf.Texts.ToString());
cmd.Parameters.AddWithValue("@companyassoci", cmbCompaniesAssoci.Texts.ToString());
cmd.Parameters.AddWithValue("@note", rtbNotes.Text.ToString());
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Insert data successfully", "Information");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Information");
conn.Close();
return;
}
}
}
}
Result from SSMS:

Design from Visual Studio:

code) that starts with "namespace REMAS.Forms.Account { public partial". This is why you are asked to "format them [your code, images, data] appropriately" when posting a question.