6
Answers

How to implement two methods in a single call?

Prasad Bhagat

Prasad Bhagat

8y
340
1
Dear All,
 
 
am writing  two methods using c#.they are
 
initially in my first method was  saves the phone number into database and return the id or phone number and status .
 
if the status is "ok" then i want to call my second method .
 
my second method was simply storing a message into database with refrence of first method id or phone number into other table .please give me some idea .how can i call these methods.give me any examples ..
 
am using simple c#,sql server. 
Answers (6)
1
Rahul Chavan

Rahul Chavan

NA 1.2k 35.7k 8y
Create a Stored Procedure add Insert trigger. In trigger write the data to new table.
 -or-
You can use @@Rowcount  to check number of rows / records inserted in the table. If it is 1 then you can add the vale in message table, if value is 0 then you should write error.
0
Vivek Kumar

Vivek Kumar

NA 7.6k 729.7k 8y
Rahul Chavan solution is looking good 
0
Rahul Chavan

Rahul Chavan

NA 1.2k 35.7k 8y
Hi Prasad
 
int numberOfRowsAffected=0;
String conString=ConfigurationManager.ConnectionStrings["myDatabaseConnectionString"].ToString();
SqlConnection conn = new SqlConnection(conString);
//Call stored Procedure
SqlCommand cmd = new SqlCommand("insertIMEIdata", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@IMEINbr", SqlDbType.NVarChar).Value = inputParameter;
conn.Open();
//numberOfRowsAffected variable will have number of rows affected
numberOfRowsAffected=cmd.ExecuteNonQuery();
//Call to your Second Method-Write your Code
conn.Close();
 
Stored Procedure Code:
 
CREATE Procedure insertIMEIdata
@IMEINbr nvarchar(50)
AS
insert into IMEIdata (IMEI) values (@IMEINbr)
GO
 
 
 
0
Prasad Bhagat

Prasad Bhagat

NA 437 90.9k 8y
Dear Rahul,
here i have two tables one is Master table thats having only two parameters like Id, IMEI with the first method am saving the IMEI number into data table .
and now am giving some result set with sucuss message and id or imei number , once the first method was completed client was received response as a "ok"
then i want to call second method  now i have a second table 2 parameters .with 2 parameters. one is from reference from 1st method and other one is data . this is my scenario. please help me .. how can i call these two methods.. and second method does not returns anything
0
Prasad Bhagat

Prasad Bhagat

NA 437 90.9k 8y
Dear Suresh ,
am Posting my code here please help to call these 2 methods using such way..
method 1:
public Resulset InsertIMEI(string imei)
{
Resulset result = new Resulset();
SqlConnection con = newSqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString); SqlCommand cmd = new SqlCommand("InsertIMEI", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@IMEI", imei);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0] != null)
{
result.StatusInd = Convert.ToInt32(ds.Tables[0].Rows[0]["StatusInd"].ToString());
result.StatusMsg = ds.Tables[0].Rows[0]["StatusMsg"].ToString(); result.ID=Convert.ToInt32(ds.Tables[0].Rows[0]["Id"].ToString());
}
return result;
}
method 2:
public void IsertImeIData(int IMEI, string Data)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString); con.Open();
SqlCommand cmd = new SqlCommand("InsertIMEIData", con);
cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@IMEIID", IMEI);
cmd.Parameters.AddWithValue("@Data", Data);
cmd.executenonquery(); 
con.Close();
}
so i want to call these two methods .please help me
 
0
Suresh M

Suresh M

NA 18.6k 1.5m 8y
return the result of first method and execute the second one or use Asynchronous Programming with Async and Await